Hugo

Fingerprint for images (how?)

Howdy there!

I’m scratching my head trying to figure out the way to setup and use the fingerprint feature for my website images. I’ve gone through the docs already looking for the answer and while it does mentions images and fingerprinting, it does so very briefly, only showing a real use case for stylesheets (much appreciate for that one!)

Can someone lend a hand please?

Thanks in advance.

Cheers!

With images in the assets/ directory, you simply do resources.Get "<IMAGE PATH>" | fingerprint.

If the images are not a assets/ directory, they need to be in a page bundle (someone correct me if that’s wrong).

Example

2 Likes

Ohhhh I see how that works. Thanks! :wink:

But how does it work for images that aren’t in the assets directory? I’ve got a bunch of images in “content/post/img”. Do all my images need to go inside the assets directory? Even those in the posts?

Currently, my images live inside the content/issue-X/ folder of every issue of my magazine. I COULD move my images to assets/issue-X/ but then I will have to also add that issue-x to the path of my image and that will break my template.

You wouldn’t have to change the image path if you used .GetMatch and wildcards

1 Like

As I mentioned, the alternative would be to make your pages Page Bundles (with index.md or _index.md as suitable) instead of regular pages.

Question, because I might not have understood how this work correctly.

I went full fingerprint with my css files.

Instead of css/style.css now I have css/style.938toasdijgokadsn0a9w5.css

Every time I upload this to my CDN provider (cloudfront), do I need to also update all the html files linking to that .css? Because the fingerprint number will change each time, right? That means, the link will change too.

So, If I have 400 html files and 1 css file:

Change
from

h1 { color: black; }

to

h1 { color: red; }

Before

  1. Upload style.css
  2. Invalidate css/style.css
  3. Drink grog

NOW

  1. Upload style.csao8i9tu89a.css
  2. Upload 400 html files scattered through 20 folders.
  3. Cry
  4. Drink grog.

Is that correct?

if it is, the only thing that I save is not having to invalidate one file, but have to pay for 400 file uploads. Not sure that’s the expected result…

Cheers.

@Javier_Cabrera please open your own thread about this remotely related topic.

I upload Hugo content and theme to the server and run hugo on the server. Syncing the content ist a lot faster for me. Could be a way for other users.

1 Like