使用 vue 写了个项目练手,发现 js 加载很慢。
js : http://www.hi-cat.cn/static/js/vendor.9af8cbe972dffd99c357.js 大小 620 k。
服务器配置 :2 核 8g 5M 带宽
nginx 版本 :1.15.8
nginx 配置 :
server {
listen 80;
listen [::]:80;
root /var/www/hi-cat.cn;
index index.html;
server_name www.hi-cat.cn;
access_log /var/log/nginx/hi-cat.access.log;
error_log /var/log/nginx/hi-cat.error.log;
location / {
try_files $uri /index.html ;
}
location /api {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
我发现页面再在加载 http://www.hi-cat.cn/static/js/vendor.9af8cbe972dffd99c357.js 的时候所使用的时间不固定 ,很多时候需要花费 3~4s 时间。
服务器上也没有跑其他程序, 我 5M 的带宽 ,为什么加载时间会这么长?
如果我的 nginx 没有开启 gzip 压缩的话 , 文件大小在 1.7m ,加载时间会达到 8s。
不考虑使用 CDN,也不考虑优化 JS,如何分析加载很慢的原因 ?