Skip to content

Commit 6e5dee3

Browse files
committed
🐛(frontend) cache hashed next static assets and revalidate html
Files under /_next/static/ carry a content hash in their name but were served without Cache-Control, so browsers fell back to heuristic freshness and revalidated each of the ~45 files of a page with a conditional request. Serve them with a one-year immutable lifetime. HTML pages, service-worker.js and public files keep a stable name: send Cache-Control: no-cache so the browser revalidates them and always gets the chunk list and service worker of the current release. The headers are repeated in every location, as nginx drops the inherited add_header directives as soon as a location defines its own. Closes #2770 Signed-off-by: Anthony LC <anthony.le-courric@mail.numerique.gouv.fr>
1 parent 2bd3031 commit 6e5dee3

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ and this project adheres to
9090
- 🐛(documentation) fix minio port and keycloak realm in the k8s guide #2751
9191
- 🐛(collaboration) bound the calls yhub makes to the backend with a timeout,
9292
`YHUB_BACKEND_REQUEST_TIMEOUT_MS`, 5s by default #2753
93+
- 🐛(frontend) cache hashed `/_next/static/` assets and revalidate HTML #2770
9394
- 🐛(backend) compensate document duplication failures #2755
9495
- 🐛(frontend) open search results in a new tab with ctrl/cmd+click #2719
9596
- 🐛(docker) pull minio images from pgsty

‎src/frontend/apps/impress/conf/default.conf‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,37 @@ server {
55

66
root /app;
77

8+
# Files under /_next/static/ have a content hash in their name: they never
9+
# change, so browsers can keep them for good.
10+
# `add_header` is not inherited when a location defines its own.
11+
location /_next/static/ {
12+
try_files $uri =404;
13+
14+
add_header Cache-Control "public, max-age=31536000, immutable";
15+
add_header X-Frame-Options DENY always;
16+
}
17+
18+
# Everything else (HTML pages, service-worker.js, public files) has a stable
19+
# name: the browser must revalidate it, so that it always gets the chunk list
20+
# of the current release and the latest service worker.
821
location / {
922
try_files $uri index.html $uri/index.html =404;
1023

24+
add_header Cache-Control "no-cache";
1125
add_header X-Frame-Options DENY always;
1226
}
1327

1428
location ~ "^/docs/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/?$" {
1529
try_files $uri /docs/[id]/index.html;
1630

31+
add_header Cache-Control "no-cache";
1732
add_header X-Frame-Options DENY always;
1833
}
1934

2035
location ~ "^/user-reconciliations/(active|inactive)/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/?$" {
2136
try_files $uri /user-reconciliations/$1/[id]/index.html;
2237

38+
add_header Cache-Control "no-cache";
2339
add_header X-Frame-Options DENY always;
2440
}
2541

0 commit comments

Comments
 (0)