缓存服务器 文件替换,通过nginx替换指纹文件服务器时,浏览器中的资产缓存过期...

Matic Jurglič

10

assets

nginx

我通过nginx提供单页JavaScript应用程序,当我部署新版本时,我想强制浏览器使其JS缓存无效并请求/使用可用的最新版本.

因此,例如,当我用命名的文件替换服务器文件夹my-app-8e8faf9.js上的文件时my-app-eaea342.js,我不希望浏览器再次my-app-8e8faf9.js从其缓存中提取.但是当没有可用的新版本时,我仍然希望他们从缓存中读取资产.

如何使用nginx配置实现此目的?这是我现有的配置:

server {

listen 80;

server_name my.server.com;

root /u/apps/my_client_production/current;

index index.html;

# ~2 seconds is often enough for most folks to parse HTML/CSS and

# retrieve needed images/icons/frames, connections are cheap in

# nginx so increasing this is generally safe...

keepalive_timeout 10;

client_max_body_size 100M;

access_log /u/apps/my_client_production/shared/log/nginx.access.log;

error_log /u/apps/my_client_production/shared/log/nginx.error.log info;

location / {

try_files $uri $uri/ =404;

gzip_static on;

expires max;

add_header Cache-Control public;

}

# Error pages

error_page 500 502 503 504 /500.html;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值