diff --git a/nginx.conf b/nginx.conf index 4a5e4ad..095793d 100644 --- a/nginx.conf +++ b/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"; + } } diff --git a/webpack.config.js b/webpack.config.js index bacac91..8630754 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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, },