The benefits of minifying JS
(1) Reduce the size of the file;
(2) Reduce network transmission volume and bandwidth occupation;
(3) Reduce the processing pressure of the server;
(4) Improve the speed of page rendering and display.
Install the uglify plugin
# 执行命令:
npm install uglify-js -g
single file compression
# 使用方法:uglifyjs + 要压缩的js文件名称 + -o + 压缩后js文件名称
uglifyjs vendor.js -o vendor.min.js
The file size is significantly smaller after compression! ! !
Bulk compression method
(1) Create a new txt file with the following content
@echo off
:: 设置压缩JS文件的根目录,脚本会自动按树层次查找和压缩所有的JS(注意路劲中不能有空格)
SET JSFOLDER=D:\uglifyDestination
echo 正在查找JS文件
chdir /d %JSFOLDER%
for /r . %%a in (*.js) do (
@echo 正在压缩 %%~a ...
uglifyjs %%~fa -m -o %%~fa
)
echo 完成!
pause & exit
(2) Modify the file to a .bat file (3) Place the js file to be compressed in the specified directory (for example: D:\uglifyDestination)
(4) Double-click the bat file to start compression
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。