I’ve got a fairly large site which uses Hugo’s image processing to generate several different sizes of images.
What I’m noticing is that every time I build my site using hugo --gc --minify
, Hugo seems to process more or less the same amount of images despite no changes being made. I believe that this is the reason why deployments to Netlify are slow with ~1000 new files being uploaded on every deploy with no changes to the site’s content.
I’ve attempted to troubleshoot as best as I can starting with the information Hugo Image Processing, which states:
Hugo caches processed images in the resources directory. If you include this directory in source control, Hugo will not have to regenerate the images in a CI/CD workflow (e.g., GitHub Pages, GitLab Pages, Netlify, etc.). This results in faster builds.
I committed the full resources
directory and it made no difference as Netlify still reports uploading ~1000 new files.
My second attempt was to use the Netlify Plugin - Hugo Cache. Although it caches the resources as shown below, it doesn’t seem to make any difference:
1. netlify-plugin-hugo-cache-resources (onPreBuild event)
Checking if resources exist at "resources"
Restored cached resources folder. Total files: 2
...
3. netlify-plugin-hugo-cache-resources (onPostBuild event)
Saved resources folder to cache. Total files: 7690
To try and isolate if this is a Hugo or Netlify issue, I removed public/
and resources/
and built my site locally three times as shown below. Each time Hugo is processing thousands of images.
Output (no previous public or resources directories):
hugo v0.95.0-9F2E76AF linux/arm64 BuildDate=2022-03-16T14:20:19Z VendorInfo=gohugoio
| EN
-------------------+--------
Pages | 10613
Paginator pages | 246
Non-page files | 1360
Static files | 6
Processed images | 8542
Aliases | 28
Sitemaps | 1
Cleaned | 0
Second run (existing public and resources directories):
hugo v0.95.0-9F2E76AF linux/arm64 BuildDate=2022-03-16T14:20:19Z VendorInfo=gohugoio
| EN
-------------------+--------
Pages | 10613
Paginator pages | 246
Non-page files | 1360
Static files | 6
Processed images | 7846
Aliases | 28
Sitemaps | 1
Cleaned | 2
Third run:
hugo v0.95.0-9F2E76AF linux/arm64 BuildDate=2022-03-16T14:20:19Z VendorInfo=gohugoio
| EN
-------------------+--------
Pages | 10613
Paginator pages | 246
Non-page files | 1360
Static files | 6
Processed images | 7781
Aliases | 28
Sitemaps | 1
Cleaned | 2
To my untrained eyes it appears that Hugo is not making use of the cached processed images in resources/
and that’s the reason for the thousands of new file uploads, but I’m not sure how to troubleshoot further.
Any thoughts from the community is much appreciated
UPDATE 1: I removed fingerprint
throughout my project and also built locally with hugo
(no garbage collection or minification) but I still see the same results.