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;
}