How to compress javascript

藏色散人
Release: 2021-10-19 14:40:43
Original
6725 people have browsed it

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. .

How to compress javascript

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~")
Copy after login

Command line operation:

uglifyjs index.js -c -m -o index.min.js
Copy after login

Then it will generate:

function log(o){console.log(o)}log("Hello~");
Copy after login

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);
}
Copy after login

My folder:

cmd: Execution

java -jar E:/yuicompressor-2.4.8.jar --type js --charset utf-8 E:\all.js > E:\all.min.js
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template