fix: add content hash to JS bundles and fix caching strategy
JS files were output as main.js without content hash, combined with nginx's 30-day immutable cache. Browsers would never fetch updated code. - Add [contenthash:8] to webpack output filenames in production - Set index.html to no-cache so browsers always check for new bundles - Only apply immutable cache to hashed filenames (*.abcdef01.js) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
091fc24d90
commit
31ea850769
15
nginx.conf
15
nginx.conf
@ -29,14 +29,23 @@ server {
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# SPA fallback
|
||||
# SPA fallback — index.html must not be cached
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
}
|
||||
|
||||
# 静态资源缓存
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
# Hashed static assets — long-term cache is safe
|
||||
location ~* \.[0-9a-f]{8}\.(js|css)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Other static assets (images, fonts) — moderate cache
|
||||
location ~* \.(png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 7d;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ module.exports = (env, argv) => {
|
||||
entry: './src/index.tsx',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: '[name].js',
|
||||
chunkFilename: '[name].chunk.js',
|
||||
filename: isDev ? '[name].js' : '[name].[contenthash:8].js',
|
||||
chunkFilename: isDev ? '[name].chunk.js' : '[name].[contenthash:8].chunk.js',
|
||||
publicPath: '/',
|
||||
clean: true,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user