Image caching is not working anymore in 0.154.2

TL;DR: It seems Hugo’s image processing is currently ignoring cache, always reprocessing all image files.

In my site, I use image processing to turn each JPG file to a fixed set of WebP files, each in a different resolution (to get responsive images). Because of this, I was using Hugo’s extended version, to be able to encode WebP files. And, to avoid making this processing in the server (which is Netlify), I usually run the JPG > WebP processing locally, so all the generated WebP files can be version-controlled. This worked fine, until now.

Today I’m updating my personal site from 0.152.2 to 0.154.2 (current). First, I tested the extended version, which took very MUCH longer than usual to build my site: Hugo reprocessed all the images, generating different filenames. But, as no error was thrown, I then tested the standard version (which since 0.153 got WebP processing). It again took way much longer than usual, and, to my surprise, all the filenames were different from the extended-generated ones. (In those tests, I’ve always ran hugo server –gc .)

Then, I stopped Hugo server and re-ran it (same Hugo version, same Hugo executable), hoping to get normal build times (as the cached files would not need to be regenerated), which in my machine are around 6 seconds. But Hugo reprocessed again all the images, ignoring the cache and, obviously, tooking much longer than expected (around 15 minutes).

I then turned back to extended version, and the results were the same: an always very long build time, despite the cache.

So, it seems to me image file caching is somewhat nor deterministic nor working anymore, and this happened between 0.152.2 and 0.154.2.

Add this to your site config to make the image cache persistent when building your site with Netlify:

[caches.images]
  dir    = ":cacheDir/images"
  maxAge = "1440h"

See details.

In this case there’s no benefit to keeping your resources directory under version control.

This is expected and desirable. There are subtle decoding and encoding changes with the v0.153.0 WebP implementation (do a file size comparison), so the cache key (and file name) must be changed.

I am unable to reproduce this as written:

git clone --single-branch -b hugo-forum-topic-56499 https://github.com/jmooring/hugo-testing hugo-forum-topic-56499
cd hugo-forum-topic-56499
hugo 
hugo

On my exceptionally average laptop, the first build takes 4 seconds, and the second build takes 0.1 seconds. I tested with both the extended and standard editions of v0.154.2. And the edition that you use from one run to the next is irrelevant.

I have not read the entire thread, but with the new webp decoder/encoder, I decided to increment the version number used in the image file hashes – which is probably what you see.

1 Like

From my experience

I moved all my sites to latest version, removed resources folder and reprocessed them, knowing that new decoder change things. After that one off reprocessing all going back to as it was previously.