1.打包方式
原来的打包方式如下:
"build": "ng build"
生成的文件中,vendor.js竟然高达3M多。
解决方法:
"build": "ng build --prod"
加了--prod参数后,angular-cli会把用不到的包都删掉
2.nginx开启gzip优化
在nginx中server上,添加这段代码
gzip on;
gzip_static on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";
# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;
参考:https://blog.csdn.net/jiezhaoliao9206/article/details/77880735