I use a quick crypto.FNV32a
-based fix for short cache-busting fingerprints that doesn’t directly rely on the unstable .Key
method.
crypto.FNV32a
to generate a short hash, then copy the resource to a new path with that fingerprint.
{{ $resource := resources.Get . -}}
{{- $target_path_formatStr := (replaceRE `(\.[^\.]*)$` ".%d$1" .) -}}
{{- $cacheBuster := $resource.Content | crypto.FNV32a -}}
{{- $target_path := printf $target_path_formatStr $cacheBuster -}}
{{- return resources.Copy $target_path $resource -}}
head
element. I invoke it using partialCached
so the fingerprinting only happens once per resource:
{{ $icon_svg := partialCached "cache-bust.html" "/favicon.svg" "/favicon.svg" }}
{{- printf `<link rel="icon" sizes="any" href="%s" type="image/svg+xml" />` $icon_svg.RelPermalink | safeHTML }}
<link rel="icon" sizes="any" href="/favicon.2229316949.svg" type="image/svg+xml"/>
Encoding it to a higher base and using alphanumerics could shave off 1-2 ch.