Skip to content

Commit ac936d4

Browse files
committed
feat: enhance nginx configuration to prevent caching of HTML files and ensure latest version of index.html is served
1 parent 5bce434 commit ac936d4

File tree

3 files changed

+96
-51
lines changed

3 files changed

+96
-51
lines changed

src/frontend/author_portal/nginx.conf

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,45 @@ http {
3131
# what file to server as index
3232
index index.html index.htm;
3333

34+
# Prevent caching of index.html to ensure users get latest version
35+
location = /index.html {
36+
add_header Cache-Control "no-cache, no-store, must-revalidate";
37+
add_header Pragma "no-cache";
38+
add_header Expires "0";
39+
try_files $uri =404;
40+
}
41+
3442
location / {
3543
# First attempt to serve request as file, then
3644
# as directory, then fall back to redirecting to index.html
3745
try_files $uri $uri/ /index.html;
38-
}
3946

40-
# Media: images, icons, video, audio, HTC
41-
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
42-
expires 1M;
43-
access_log off;
44-
add_header Cache-Control "public";
45-
}
47+
# Prevent caching of HTML files
48+
location ~* \.html$ {
49+
add_header Cache-Control "no-cache, no-store, must-revalidate";
50+
add_header Pragma "no-cache";
51+
add_header Expires "0";
52+
}
4653

47-
# Javascript and CSS files
48-
location ~* \.(?:css|js)$ {
49-
try_files $uri =404;
50-
expires 1y;
51-
access_log off;
52-
add_header Cache-Control "public";
53-
}
54+
# Media: images, icons, video, audio, HTC
55+
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
56+
expires 1M;
57+
access_log off;
58+
add_header Cache-Control "public";
59+
}
5460

55-
# Any route containing a file extension (e.g. /devicesfile.js)
56-
location ~ ^.+\..+$ {
57-
try_files $uri =404;
61+
# Javascript and CSS files (with content hash in filename)
62+
location ~* \.(?:css|js)$ {
63+
try_files $uri =404;
64+
expires 1y;
65+
access_log off;
66+
add_header Cache-Control "public, immutable";
67+
}
68+
69+
# Any route containing a file extension (e.g. /devicesfile.js)
70+
location ~ ^.+\..+$ {
71+
try_files $uri =404;
72+
}
5873
}
5974
}
6075
}

src/frontend/curator_dashboard/nginx.conf

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,45 @@ http {
4040
allow all;
4141
}
4242

43+
# Prevent caching of index.html to ensure users get latest version
44+
location = /index.html {
45+
add_header Cache-Control "no-cache, no-store, must-revalidate";
46+
add_header Pragma "no-cache";
47+
add_header Expires "0";
48+
try_files $uri =404;
49+
}
50+
4351
location / {
4452
# First attempt to serve request as file, then
4553
# as directory, then fall back to redirecting to index.html
4654
try_files $uri $uri/ /index.html;
47-
}
4855

49-
# Media: images, icons, video, audio, HTC
50-
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
51-
expires 1M;
52-
access_log off;
53-
add_header Cache-Control "public";
54-
}
56+
# Prevent caching of HTML files
57+
location ~* \.html$ {
58+
add_header Cache-Control "no-cache, no-store, must-revalidate";
59+
add_header Pragma "no-cache";
60+
add_header Expires "0";
61+
}
5562

56-
# Javascript and CSS files
57-
location ~* \.(?:css|js)$ {
58-
try_files $uri =404;
59-
expires 1y;
60-
access_log off;
61-
add_header Cache-Control "public";
62-
}
63+
# Media: images, icons, video, audio, HTC
64+
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
65+
expires 1M;
66+
access_log off;
67+
add_header Cache-Control "public";
68+
}
6369

64-
# Any route containing a file extension (e.g. /devicesfile.js)
65-
location ~ ^.+\..+$ {
66-
try_files $uri =404;
70+
# Javascript and CSS files (with content hash in filename)
71+
location ~* \.(?:css|js)$ {
72+
try_files $uri =404;
73+
expires 1y;
74+
access_log off;
75+
add_header Cache-Control "public, immutable";
76+
}
77+
78+
# Any route containing a file extension (e.g. /devicesfile.js)
79+
location ~ ^.+\..+$ {
80+
try_files $uri =404;
81+
}
6782
}
6883
}
6984
}

src/frontend/submission_form/nginx.conf

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,45 @@ http {
3131
# what file to server as index
3232
index index.html index.htm;
3333

34+
# Prevent caching of index.html to ensure users get latest version
35+
location = /index.html {
36+
add_header Cache-Control "no-cache, no-store, must-revalidate";
37+
add_header Pragma "no-cache";
38+
add_header Expires "0";
39+
try_files $uri =404;
40+
}
41+
3442
location / {
3543
# First attempt to serve request as file, then
3644
# as directory, then fall back to redirecting to index.html
3745
try_files $uri $uri/ /index.html;
38-
}
3946

40-
# Media: images, icons, video, audio, HTC
41-
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
42-
expires 1M;
43-
access_log off;
44-
add_header Cache-Control "public";
45-
}
47+
# Prevent caching of HTML files
48+
location ~* \.html$ {
49+
add_header Cache-Control "no-cache, no-store, must-revalidate";
50+
add_header Pragma "no-cache";
51+
add_header Expires "0";
52+
}
4653

47-
# Javascript and CSS files
48-
location ~* \.(?:css|js)$ {
49-
try_files $uri =404;
50-
expires 1y;
51-
access_log off;
52-
add_header Cache-Control "public";
53-
}
54+
# Media: images, icons, video, audio, HTC
55+
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
56+
expires 1M;
57+
access_log off;
58+
add_header Cache-Control "public";
59+
}
5460

55-
# Any route containing a file extension (e.g. /devicesfile.js)
56-
location ~ ^.+\..+$ {
57-
try_files $uri =404;
61+
# Javascript and CSS files (with content hash in filename)
62+
location ~* \.(?:css|js)$ {
63+
try_files $uri =404;
64+
expires 1y;
65+
access_log off;
66+
add_header Cache-Control "public, immutable";
67+
}
68+
69+
# Any route containing a file extension (e.g. /devicesfile.js)
70+
location ~ ^.+\..+$ {
71+
try_files $uri =404;
72+
}
5873
}
5974
}
6075
}

0 commit comments

Comments
 (0)