add more aggressive headers to prevent caching the root.

This commit is contained in:
Evan
2025-03-18 09:57:28 -07:00
parent fe3b4fb8cc
commit 388aafbbf5
2 changed files with 16 additions and 23 deletions
+10 -22
View File
@@ -176,15 +176,18 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}
# Updated Root location - with 1 second cache
# Root location with no caching
location = / {
proxy_pass http://127.0.0.1:3000;
add_header Cache-Control "public, max-age=1"; # 1 second cache
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
proxy_cache STATIC;
proxy_cache_valid 200 302 1s; # Cache successful responses for 1 second
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
# Disable proxy cache for index.html
proxy_no_cache 1;
proxy_cache_bypass 1;
# Show cache status in response headers
add_header X-Cache-Status $upstream_cache_status;
proxy_http_version 1.1;
@@ -196,22 +199,7 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}
# Location for index.html specifically
location ~* /index\.html$ {
proxy_pass http://127.0.0.1:3000;
add_header Cache-Control "public, max-age=1";
proxy_cache STATIC;
proxy_cache_valid 200 302 1s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Default location for all other requests
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
+6 -1
View File
@@ -30,9 +30,14 @@ app.use(
// You can conditionally set different cache times based on file types
if (path.endsWith(".html")) {
// Set HTML files to no-cache to ensure Express doesn't send 304s
res.setHeader("Cache-Control", "no-cache, must-revalidate");
res.setHeader(
"Cache-Control",
"no-store, no-cache, must-revalidate, proxy-revalidate",
);
res.setHeader("Pragma", "no-cache");
res.setHeader("Expires", "0");
// Prevent conditional requests
res.setHeader("ETag", "");
} else if (path.match(/\.(js|css|svg)$/)) {
// JS, CSS, SVG get long cache with immutable
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");