文章目录[隐藏]
前言
有些js的体积过大,动辄好几M,导致下载这个js文件都要花好几秒,这个时候需要压缩js。
使用UglifyJS
step 1:
1 |
npm install uglify-js -g |
step 2:
打开windows cmd 命令行窗口, 运行如下命令:
1 |
uglifyjs sample.js -c -m -o sample.min.js |
nginx 缓存js
1 2 3 4 5 6 7 8 9 |
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 15d; } location ~ .*\.(js|css)?$ { expires 1d; } |