Cache busting assets in page bundles?

Is there a way to cache bust assets in page bundles? For example, one can assign post-related image files a very long browser TTL. Updating images in posts would naturally cause browsers to re-request the image from the server.

Does this work for you ?

Not sure if I understand, it sounds like the cachebusters options only work for JS and stylesheets?

content/
└── posts/
    └── post-1/
        β”œβ”€β”€ a.jpg
        └── index.md

layouts/_default/single.html

{{ with .Resources.Get "a.jpg" | fingerprint }}
  <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}

You can optionally add an SRI hash at the same time:

{{ with .Resources.Get "a.jpg" | fingerprint }}
  <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ end }}

If you want to fingerprint images that are reference via markdown links, use an image render hook, perhaps starting with Hugo’s embedded image render hook as a model:

https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/_markup/render-image.html

1 Like

Looks like fingerprinting can’t be automated but some manual setup would make it work. Thanks!

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