Home > Article > Web Front-end > How to compress javascript
Javascript compression method: 1. Install nodeJs; 2. Create a new index.js; 3. Run the "uglifyjs index.js -c -m -o index.min.js" command on the command line. .
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to compress javascript?
js compression method:
1. uglifyjs
First install nodeJs
Create a new index.js
function log(text){ console.log(text) } log("Hello~")
Command line operation:
uglifyjs index.js -c -m -o index.min.js
Then it will generate:
function log(o){console.log(o)}log("Hello~");
2, yuicompressor
Download address
https ://github.com/yui/yuicompressor
New yuitest.js
var btn = document.getElementById("b1"); btn.onclick = function(){ console.log(1); console.log(2); console.log(3); console.log(4); console.log(5); console.log(6); }
My folder:
cmd: Execution
java -jar E:/yuicompressor-2.4.8.jar --type js --charset utf-8 E:\all.js > E:\all.min.js
completed.
Recommended study: "javascript basic tutorial"
The above is the detailed content of How to compress javascript. For more information, please follow other related articles on the PHP Chinese website!