refactor: update caching strategy for JavaScript files
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.
This commit is contained in:
Juan Sebastián Montoya 2025-11-26 19:40:06 -05:00
parent 5d6271f60c
commit ab82a6f874

View file

@ -9,11 +9,19 @@ server {
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
} }
# Prevent caching of JavaScript files and version.json # Cache JavaScript files with version query params for 1 year (immutable)
location ~* \.(js|mjs)$ { # 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 Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache"; add_header Pragma "no-cache";
add_header Expires "0"; add_header Expires "0";
}
add_header Vary "Accept-Encoding"; add_header Vary "Accept-Encoding";
} }