Bug: Doc says fingerprint is in Resource.Data.Digest

From resource package - github.com/gohugoio/hugo/resource - Go Packages

// Resource specific data set by Hugo.
// One example would be.Data.Digest for fingerprinted resources.
Data() interface{}

But it seems to be in Resource.Data.Integrity.

Also, there’s a typo: be.Data.Digestbe .Data.Digest.

Wasn’t sure whether to file bugs under support or dev.

(Good lord, this Discourse auto link preview thing is bad.)

@bep Thanks for the fix.

On a related note, the fingerprint doc doesn’t say whether processed image resources should be fingerprinted. It’s unclear because processed images seem to have some kind of hash in their name. I’ve been fingerprinting them just in case, since the image processing doc doesn’t specify the file name at all. It would be useful for the doc to say what’s recommended to do.

If I understand your question, the HTML spec allows the integrity attribute for link and script elements only.

Editor’s Draft, 30 November 2022
https://w3c.github.io/webappsec-subresource-integrity/#verification-of-html-document-subresources

Note: A future revision of this specification is likely to include integrity support for all possible subresources, i.e., a , audio , embed , iframe , img , link , object , script , source , track , and video elements.

@jmooring I’m asking whether I need to do this:

{{ $res := resources.Get "myimg.jpg" }}
{{ $res = $res.Resize $options | fingerprint }}

Or if I can just do this:

{{ $res := resources.Get "myimg.jpg" }}
{{ $res = $res.Resize $options }}

Fingerprint appends a hash to the file name:

http://localhost:1313/blog/2023/01/05/gallery-shortcode/1-1_hu7fe894556d5c3bf4f69887ccbae1cdcb_1145441_550x0_resize_q75_h1_lanczos.7baa0db88a4eabb2f5706e4225168824611565eb0e81e79afa6a67c15f741af1.webp

Without it, there appears to still be some kind of hash:

http://localhost:1313/blog/2023/01/05/gallery-shortcode/1-1_hu7fe894556d5c3bf4f69887ccbae1cdcb_1145441_550x0_resize_q75_h1_lanczos.webp

Is that actually a hash, like MD5 or SHA1? Will it always be there, such that it’s safe to never use fingerprint on it? I can’t tell from the API documentation.

Edit: Fixed code.

You might want to read up about the usage of the integrity attribute, as @jmooring suggested. There’s currently no point in calculating the fingerprint of an img since it doesn’t have an integrity attribute (yet?).

You do not.

The filename is the key for the image cache (typically resources/_gen/images).

1 Like

OK, thanks.

It would be helpful to document that in the fingerprint documentation.

You might want to read up about the usage of the integrity attribute, as @jmooring suggested. There’s currently no point in calculating the fingerprint of an img since it doesn’t have an integrity attribute (yet?).

@chrillek The fingerprint function is, in part, for making a resource URL change when the file content changes, e.g. .css or .js. It can also be used for unprocessed images like .jpg. My question was whether it needs to be used for processed images too.

Edit: Changing the file name when the contents change ensures that browsers don’t cache old content.

We try to document where to use something, not all the places where you should not use something.

In my opinion, that doesn’t work well when a feature is possibly redundant when used with another feature.

I couldn’t find guidance either way in the documentation, which is why I came here.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.