Skip to content

Commit 44373b2

Browse files
committed
Revert "config.js: cache-bust via ?v=<commit> in index.html script tag"
This reverts commit 3ea9c71.
1 parent 3ea9c71 commit 44373b2

3 files changed

Lines changed: 16 additions & 22 deletions

File tree

frontend/angular.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
"src/customize.js",
174174
"src/config.template.js",
175175
"src/_redirects",
176+
"src/_headers",
176177
{
177178
"glob": "*.css",
178179
"input": ".theme-build",
@@ -198,7 +199,8 @@
198199
"assets": [
199200
"src/favicon.ico",
200201
"src/robots.txt",
201-
"src/_redirects"
202+
"src/_redirects",
203+
"src/_headers"
202204
],
203205
"fileReplacements": [
204206
{

frontend/generate-config.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,6 @@ if (process.env.DOCKER_COMMIT_HASH) {
9696
}
9797
}
9898

99-
// HACK -- Ordpool: cache-bust config.js / customize.js by appending
100-
// `?v=<gitCommitHash>` to their <script src> in index.html. These files
101-
// aren't fingerprinted (Angular only hashes its own bundles), so without
102-
// the query suffix the browser keeps reading the previous build's
103-
// window.__env until /resources/config.js's max-age expires. Same trick
104-
// Angular uses for its bundle filenames -- different URL per deploy
105-
// forces a fresh fetch; matching ETag still 304's when content is
106-
// unchanged.
107-
try {
108-
const stamp = gitCommitHash || Date.now().toString(36);
109-
let indexHtml = fs.readFileSync('src/index.html', 'utf-8');
110-
indexHtml = indexHtml.replace(
111-
/<script\s+src="\/resources\/(config|customize)\.js(?:\?[^"]*)?"><\/script>/g,
112-
`<script src="/resources/$1.js?v=${stamp}"></script>`,
113-
);
114-
fs.writeFileSync('src/index.html', indexHtml);
115-
console.log(`Cache-busted /resources/{config,customize}.js in src/index.html with v=${stamp}`);
116-
} catch (e) {
117-
console.log('Warning: could not cache-bust resources/config.js in index.html:', e.message);
118-
}
119-
12099
const newConfig = `(function (window) {
121100
window.__env = window.__env || {};${settings.reduce((str, obj) => `${str}
122101
window.__env.${obj.key} = ${typeof obj.value === 'string' ? `'${obj.value}'` : obj.value};`, '')}

frontend/src/_headers

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Cloudflare Pages _headers — Cache-Control overrides for files that
2+
# change on every deploy but aren't fingerprinted in the URL. Wired into
3+
# the build via angular.json (assets) and shipped in dist/.
4+
#
5+
# Without this, Pages defaults to a multi-hour TTL on .js files, so
6+
# already-open tabs keep reading the previous build's window.__env
7+
# (GIT_COMMIT_HASH, BASE_MODULE, etc.) until their cache expires. ETag
8+
# revalidation closes the gap to one 304 round-trip per page load.
9+
/resources/config.js
10+
Cache-Control: public, max-age=0, must-revalidate
11+
12+
/resources/customize.js
13+
Cache-Control: public, max-age=0, must-revalidate

0 commit comments

Comments
 (0)