Debian Codegraph @

docs/content/en/functions/resources/Fingerprint.md

raw
1 ---
2 title: resources.Fingerprint
3 description: Returns a fingerprinted resource, created by cryptographically hashing the content of the given resource.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [fingerprint]
9 returnType: resource.Resource
10 signatures: ['resources.Fingerprint [ALGORITHM] RESOURCE']
11 ---
12
13 {{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
14
15 ```go-html-template
16 {{ with resources.Get "js/main.js" }}
17 {{ with . | fingerprint "sha256" }}
18 <script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
19 {{ end }}
20 {{ end }}
21 ```
22
23 Hugo renders this to something like:
24
25 ```html
26 <script src="/js/main.62e...df1.js" integrity="sha256-Yuh...rfE=" crossorigin="anonymous"></script>
27 ```
28
29 Although most commonly used with CSS and JavaScript resources, you can use the `resources.Fingerprint` function with any resource type.
30
31 The hash algorithm may be one of `md5`, `sha256` (default), `sha384`, or `sha512`.
32
33 After cryptographically hashing the resource content:
34
35 1. The values returned by the `Permalink` and `RelPermalink` methods include the hash sum
36 1. 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
37
38 [Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity