Skip to content

Commit 5b4cc29

Browse files
committed
Add cache busting to custom CSS loading
1 parent a3e4283 commit 5b4cc29

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

_includes/custom_js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<script type="text/javascript" src="/assets/js/custom.js"></script>
1+
<script type="text/javascript" src="/assets/js/custom.js?_={{ site.time | date: "%Y-%m-%d-%H" }}"></script>

assets/js/custom.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ function loadGoatCounterViews() {
1717
}
1818

1919
function loadCustomCSS() {
20+
const now = new Date();
21+
const year = now.getFullYear();
22+
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-based
23+
const day = String(now.getDate()).padStart(2, '0');
24+
const hour = String(now.getHours()).padStart(2, '0');
25+
const cacheBuster = `${year}-${month}-${day}-${hour}`;
26+
2027
const css = document.createElement('link');
2128
css.rel = 'stylesheet';
22-
css.href = '/assets/css/custom.css';
29+
// year-month-day-hour
30+
css.href = '/assets/css/custom.css?_=' + cacheBuster;
2331
document.head.appendChild(css);
2432
}
2533

0 commit comments

Comments
 (0)