Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

工程部署规范 #85

Open
peng-yin opened this issue Jul 20, 2022 · 0 comments
Open

工程部署规范 #85

peng-yin opened this issue Jul 20, 2022 · 0 comments

Comments

@peng-yin
Copy link
Owner

一、所有前端工程打包时, 都需要对文件进行版本管理, 避免缓存命中错误

  •      webpack对生成产物进行hash处理
  •      组件类、公共业务类代码需要在部署路径上携带版本号

二、所有前端工程 NG 部署时都需要配置缓存策略

  • 策略: 对html文件不缓存, 其他文件缓存7天 
  • 原理: 前端spa工程部署时, 有且仅有一个index.html作为入口文件, 如果该文件被缓存会导致用户访问的资源引用错误, 由于该文件体积极小(<1kb), 因此不设置缓存

三、工程范围及策略:

  • html文件文件不缓存, js、css文件缓存7天, img、font文件缓存30天
  • static 、res 等资源类服务: js、css、img、font 文件缓存90天 

参考:  

server {
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    #gzip_http_version [1.0;](http://xx.com;)
    gzip_comp_level 2;
    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;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";
    listen 8010;
    server_name localhost;
 
 
    error_page 500 502 503 504 /[50x.html;]http://xx.com;)
    root html/dist;
    location / {
        index [index.html;](http://xxx.com)
        try_files $uri $uri/ /[index.html;](http://xxx.com)
    }
    location ~* \.(html)$ {
        access_log off;
        add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
    }
    location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
        access_log off;
        add_header Cache-Control max-age=604800;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant