All checks were successful
Build and Publish Docker Image / Build and Validate (pull_request) Successful in 10s
- Modified caching behavior for JavaScript files to cache those with version query parameters for 1 year (immutable). - Ensured that files without version parameters are not cached, improving cache management and reducing potential stale content issues. This change enhances the efficiency of resource loading in production environments.
46 lines
1.3 KiB
Nginx Configuration File
46 lines
1.3 KiB
Nginx Configuration File
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
location / {
|
|
try_files $uri $uri/ =404;
|
|
}
|
|
|
|
# Cache JavaScript files with version query params for 1 year (immutable)
|
|
# Files without version params are not cached
|
|
location ~* \.(js|mjs)(\?v=[^&]+)?$ {
|
|
if ($args ~ "v=") {
|
|
# Has version param - cache for 1 year (immutable)
|
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|
}
|
|
if ($args !~ "v=") {
|
|
# No version param - don't cache
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
add_header Pragma "no-cache";
|
|
add_header Expires "0";
|
|
}
|
|
add_header Vary "Accept-Encoding";
|
|
}
|
|
|
|
location = /version.json {
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
add_header Pragma "no-cache";
|
|
add_header Expires "0";
|
|
}
|
|
|
|
# Prevent caching of HTML
|
|
location ~* \.html$ {
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
add_header Pragma "no-cache";
|
|
add_header Expires "0";
|
|
}
|
|
|
|
# Enable gzip compression
|
|
gzip on;
|
|
gzip_types text/html text/css application/javascript;
|
|
gzip_min_length 1000;
|
|
}
|
|
|