mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-10 00:12:09 +00:00
Implement cache-busting and SRI for CSS
Use Hugo's fingerprinting pipes [0] to give external stylesheets an identifier to enable cache-busting [1]. Since Hugo's fingerprinting automatically generates the information needed for SRI [2], include an integrity attribute too. I discovered this feature through webhint [3], and added the .hintrc file I used to the repo root. [0]: https://gohugo.io/hugo-pipes/fingerprint/ [1]: https://css-tricks.com/strategies-for-cache-busting-css/ [2]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity [3]: https://webhint.io/
This commit is contained in:
parent
7c8b40ac4c
commit
74e939f40b
3 changed files with 48 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
public/
|
||||
public_*/
|
||||
hint-report/
|
||||
|
|
43
.hintrc
Normal file
43
.hintrc
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"extends": [
|
||||
"web-recommended"
|
||||
],
|
||||
"connector": {
|
||||
"name": "puppeteer",
|
||||
"options": {
|
||||
"browser": "Chromium",
|
||||
"headless": false
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
">.01%, last 2 versions, not dead"
|
||||
],
|
||||
"hints": {
|
||||
"axe/other": "error",
|
||||
"https-only": "error",
|
||||
"doctype": "error",
|
||||
"no-broken-links": "error",
|
||||
"performance-budget": "error",
|
||||
"compat-api/css": "error",
|
||||
"compat-api/html": [
|
||||
"error",
|
||||
{
|
||||
"ignore": [
|
||||
"time",
|
||||
"picture"
|
||||
]
|
||||
}
|
||||
],
|
||||
"http-compression": [
|
||||
"warning",
|
||||
{
|
||||
"html": {
|
||||
"brotli": false
|
||||
},
|
||||
"resource": {
|
||||
"brotli": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -17,10 +17,11 @@
|
|||
{{ if not (eq $dark "off") -}}
|
||||
{{ $resources = $resources | append (resources.Get "css/dark.css" | resources.ExecuteAsTemplate "dark.css" .) -}}
|
||||
{{ end -}}
|
||||
{{ $css := $resources | resources.Concat "css/style.css" | minify }}
|
||||
{{ printf `<link rel="stylesheet" href="%s">` $css.RelPermalink | safeHTML }}
|
||||
{{ $css := $resources | resources.Concat "css/style.css" | minify | resources.Fingerprint "sha384" -}}
|
||||
{{ printf `<link rel="stylesheet" href="%s" integrity="%s">` $css.RelPermalink $css.Data.Integrity | safeHTML }}
|
||||
{{ if .Params.highlight -}}
|
||||
{{ printf `<link rel="stylesheet" href="/css/syntax.css">` | safeHTML }}
|
||||
{{ $css_syntax := resources.Get "/css/syntax.css" | minify | resources.Fingerprint "sha384" }}
|
||||
{{- printf `<link rel="stylesheet" href="%s" integrity="%s">` $css_syntax.RelPermalink $css_syntax.Data.Integrity | safeHTML }}
|
||||
{{ end -}}
|
||||
|
||||
{{ if eq .RelPermalink "/" -}}
|
||||
|
|
Loading…
Reference in a new issue