Skip to content

Conversation

@dscho
Copy link
Member

@dscho dscho commented Apr 2, 2025

Changes

  • Implement Cache Busting for the .js/.css files.

Context

When new versions of the JavaScript and CSS files are deployed, for a while some users' browsers will still hold onto cached versions of them and the style or JavaScript-based functionality might still be messed up. Even if the browser caches do not have the stale files, the CDN still might have them.

To avoid running afoul of stale cached versions of these files, employ the simple-yet-effective method of using a filename suffix that is based on the file's contents. That way, there cannot be a stale cached copy of the file under the same filename.

While at it, fix the indentation of the JavaScript file which I had inadvertently made incorrect in #1980.

dscho added 2 commits April 2, 2025 12:43
This file wants to use spaces only for indentation. However, by accident
I introduced tab characters (oh my, am I glad that I do not have to get
this reviewed on the Git mailing list) in 41436cc (application.js:
allow for relative URLs, 2025-03-15).

Let me fix that really quickly.

Signed-off-by: Johannes Schindelin <[email protected]>
When the JavaScript or CSS files are updated, caching rules often
prevent the new versions from being picked up, whether due to
browser-side caching or server-side caching.

Let's avoid this by fingerprinting the files as described in
https://gohugo.io/functions/resources/fingerprint/. We are technically
not even interested in the cryptographic aspect of this, the only
benefit we are looking for is that the file _names_ change in a
predictable manner based on the file _contents_ (similar to how Git
objects work...).

While we are technically not interested in the cryptographic aspect, we
can just as well benefit from it by adding the corresponding `integrity`
attribute. However, we only do that if the base URL indicates that this
will be accessed via HTTPS; Otherwise loading the pages locally via
`file:///` would no longer work for those resources (see
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
for more information about this issue).

Inspired-by: Toon Claes <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
@dscho dscho merged commit d16da59 into git:gh-pages Apr 3, 2025
1 check passed
@dscho dscho deleted the js-css-fixes branch April 3, 2025 11:38
@To1ne
Copy link
Collaborator

To1ne commented Apr 3, 2025

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants