Skip to content

Commit d16da59

Browse files
committed
Merge branch 'js-css-fixes'
This topic brings an indentation fix, and more importantly a fix where stale CSS/JS files are no longer used, by virtue of employing a technique called "cache busting" (see e.g. https://johnjago.com/cache-busting-hugo/). The idea is to add a filename suffix that is computed from the file contents. That way, it is guaranteed that: 1) The files can still be cached efficiently, and 2) Stale copies of the files are not used because they have a different filename. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 64bbe0e + 4482611 commit d16da59

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

assets/js/application.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ var Search = {
408408
(async () => {
409409
const pagefindURL =
410410
`${baseURLPrefix}pagefind/pagefind.js`
411-
// adjust the `baseURLPrefix` if it is relative: the `import`
412-
// is relative to the _script URL_ here, which is in /js/.
413-
// That is different from other uses of `baseURLPrefix`, which
414-
// replace `href` and `src` attributes which are relative to the
415-
// page itself that is outside of /js/.
411+
// adjust the `baseURLPrefix` if it is relative: the `import`
412+
// is relative to the _script URL_ here, which is in /js/.
413+
// That is different from other uses of `baseURLPrefix`, which
414+
// replace `href` and `src` attributes which are relative to the
415+
// page itself that is outside of /js/.
416416
.replace(/^\.\//, '../')
417417
Search.pagefind = await import(pagefindURL);
418418
const options = {

layouts/_default/baseof.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ <h1>Redirecting&hellip;</h1>
6464

6565
<link href="{{ relURL "favicon.ico" }}" rel='shortcut icon' type='image/x-icon'>
6666

67-
{{ $style := resources.Get "sass/application.scss" | resources.ExecuteAsTemplate "application.scss" . | css.Sass | resources.Minify }}
68-
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
67+
{{ $style := resources.Get "sass/application.scss" | resources.ExecuteAsTemplate "application.scss" . | css.Sass | resources.Minify | fingerprint }}
68+
<link rel="stylesheet" href="{{ $style.RelPermalink }}"{{ if (hasPrefix .Site.BaseURL "https://") }} integrity="{{ $style.Data.Integrity }}"{{ end }}>
6969
<!--[if (gte IE 6)&(lte IE 8)]>
7070
<script src="{{ relURL "js/selectivizr-min.js" }}"></script>
7171
<![endif]-->

layouts/partials/footer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
<script src="{{ relURL "js/modernizr.js" }}"></script>
1919
<script src="{{ relURL "js/modernize.js" }}"></script>
2020
{{ if eq (.Scratch.Get "section") "search" }}<script src="{{ relURL "pagefind/pagefind-ui.js" }}"></script>{{ end }}
21-
{{ $js := resources.Get "js/application.js" | resources.ExecuteAsTemplate "js/application.js" . | resources.Minify }}
22-
<script src="{{ $js.RelPermalink }}"></script>
21+
{{ $js := resources.Get "js/application.js" | resources.ExecuteAsTemplate "js/application.js" . | resources.Minify | fingerprint }}
22+
<script src="{{ $js.RelPermalink }}"{{ if (hasPrefix .Site.BaseURL "https://") }} integrity="{{ $js.Data.Integrity }}"{{ end }}></script>

tests/git-scm.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ test('404', async ({ page }) => {
254254
await expect(page.locator('.inner h1')).toHaveText(`That page doesn't exist.`)
255255

256256
// the 404 page should be styled
257-
await expect(page.locator('link[rel="stylesheet"]')).toHaveAttribute('href', /application(\.min)?\.css$/)
257+
await expect(page.locator('link[rel="stylesheet"]')).toHaveAttribute('href', /application(\.min)?(\.[0-9a-f]+)?\.css$/)
258258

259259
// the search box is shown
260260
await expect(page.locator('#search-text')).toBeVisible()

0 commit comments

Comments
 (0)