hugo/docs/content/en/functions/resources/Fingerprint.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.5 KiB

title description categories keywords action
resources.Fingerprint Cryptographically hashes the content of the given resource.
aliases related returnType signatures
fingerprint
functions/js/Build
functions/resources/Babel
functions/resources/Minify
functions/resources/PostCSS
functions/resources/PostProcess
functions/resources/ToCSS
resource.Resource
resources.Fingerprint [ALGORITHM] RESOURCE
{{ with resources.Get "js/main.js" }}
  {{ with . | fingerprint "sha256" }}
    <script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
  {{ end }}
{{ end }}

Hugo renders this to something like:

<script src="/js/main.62e...df1.js" integrity="sha256-Yuh...rfE=" crossorigin="anonymous"></script>

Although most commonly used with CSS and JavaScript resources, you can use the resources.Fingerprint function with any resource type.

The hash algorithm may be one of md5, sha256 (default), sha384, or sha512.

After cryptographically hashing the resource content:

  1. The values returned by the .Permalink and .RelPermalink methods include the hash sum
  2. The resource's .Data.Integrity method returns a Subresource Integrity (SRI) value consisting of the name of the hash algorithm, one hyphen, and the base64-encoded hash sum