Skip to content

Commit 0454d7d

Browse files
committed
feat(demo): regenerate cache-busting URL param on refresh
1 parent 4f9f174 commit 0454d7d

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

docs/index.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
<body>
1212
<div class="demo__source-bar" id="source-bar">
1313
<div class="container">
14+
Loading source info...
1415
</div>
1516
</div>
16-
<div class="container">
17-
<h1>Python Friendly Error Messages - Demo</h1>
18-
</div>
1917

20-
<div id="demo-container" class="demo__table-page">
18+
<h1>Python Friendly Error Messages - Demo</h1>
19+
20+
<div class="demo__table-page" id="demo-container">
2121
Loading demo...
2222
</div>
2323

@@ -26,7 +26,16 @@ <h1>Python Friendly Error Messages - Demo</h1>
2626

2727
const pageParams = new URLSearchParams(window.location.search);
2828
const useLocal = pageParams.has('local');
29-
const cacheBust = pageParams.get('cb');
29+
const navigationEntry = performance.getEntriesByType('navigation')[0];
30+
const isReload = navigationEntry && navigationEntry.type === 'reload';
31+
let cacheBust = pageParams.get('cb');
32+
33+
if (isReload) {
34+
cacheBust = String(Date.now());
35+
pageParams.set('cb', cacheBust);
36+
const nextUrl = `${window.location.pathname}?${pageParams.toString()}${window.location.hash}`;
37+
window.history.replaceState(null, '', nextUrl);
38+
}
3039

3140
const libPathBase = useLocal
3241
? '../dist/index.browser.js'
@@ -38,7 +47,7 @@ <h1>Python Friendly Error Messages - Demo</h1>
3847
async function initDemo() {
3948
const container = document.getElementById('demo-container');
4049

41-
const switchUrl = useLocal ? 'index.html' : 'index.html?local';
50+
const switchUrl = useLocal ? 'index.html' : 'index.html?local=true';
4251
const bar = document.querySelector('#source-bar .container');
4352
if (useLocal) {
4453
bar.innerHTML = `

docs/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ body {
1919

2020
h1 {
2121
color: #2c3e50;
22-
margin-bottom: 0.5rem;
22+
text-align: center;
2323
}
2424

2525
.demo__source-bar {

0 commit comments

Comments
 (0)