Skip to content

Commit 208992e

Browse files
fix: auto-version css/js assets to prevent stale cache issues
1 parent c7da9db commit 208992e

5 files changed

Lines changed: 10 additions & 5 deletions

File tree

container/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ git log -1
1313
export GITHUB_TOKEN="${GITHUB_TOKEN}"
1414
npm clean-install
1515
node --run all
16+
17+
# Replace cache-busting placeholder with the current commit SHA for deployed assets.
18+
ASSET_VERSION="$(git rev-parse --short=12 HEAD)"
19+
find website -type f \( -name "*.html" -o -name "*.js" -o -name "*.css" \) \
20+
-exec sed -i "s/__ASSET_VERSION__/${ASSET_VERSION}/g" {} +
1621
EOF
1722

1823
FROM nginxinc/nginx-unprivileged:alpine-slim

website/card.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { openHintsDialog } from "./hints-dialog.js";
1+
import { openHintsDialog } from "./hints-dialog.js?v=__ASSET_VERSION__";
22

33
const cardTemplate = document.getElementById("card-template");
44

website/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>MagicMirror² 3rd Party Modules</title>
77
<link rel="icon" type="image/x-icon" href="favicon.svg" />
8-
<link rel="stylesheet" href="index.css" />
8+
<link rel="stylesheet" href="index.css?v=__ASSET_VERSION__" />
99
<link
1010
rel="stylesheet"
1111
href="fonts/line-awesome-1.3.0/css/line-awesome.min.css"
@@ -196,6 +196,6 @@ <h3 id="hints-dialog-title"></h3>
196196
</div>
197197
</dialog>
198198

199-
<script src="script.js" type="module"></script>
199+
<script src="script.js?v=__ASSET_VERSION__" type="module"></script>
200200
</body>
201201
</html>

website/result.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>Result of the module analysis</title>
55
<link rel="icon" type="image/x-icon" href="favicon.svg" />
6-
<link rel="stylesheet" href="result.css" />
6+
<link rel="stylesheet" href="result.css?v=__ASSET_VERSION__" />
77
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
88
</head>
99
<body>

website/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createCard } from "./card.js";
1+
import { createCard } from "./card.js?v=__ASSET_VERSION__";
22

33
let allModules = [];
44
let skippedModules = [];

0 commit comments

Comments
 (0)