nginxでシングルページのJavaScriptアプリケーションを提供しています。新しいバージョンをデプロイするときに、ブラウザにJSキャッシュを無効にして最新のバージョンを要求/利用可能です。nginx経由でフィンガープリントファイルサーバーを置き換えるときにブラウザの資産キャッシュが失効する
たとえば、サーバーフォルダのファイル名を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;
}