_gen resources and images

I’m planning to use hugo to reimplement a number of websites that display large numbers of high-resolution photographs. Using hugo’s magical image processing features, I plan to convert the source images to multiple formats (JPEG, AVIF, WEBP) at multiple resolutions.

Between the high-quality source images and the multiple copies to be served to users, these sites promise to take up a fair amount of disk space. I’ve now noticed, however, that hugo also stores a copy of all resources processed in the resources/_gen directory, effectively doubling the space required for each site. It looks as if deleting the images in resources/_gen causes hugo to reprocess everything, so simply blowing away resources/_gen after a successful build isn’t really an option.

Is there a way to make hugo less greedy, or do I just need a bigger VPS?

The resources directory is where, by default, Hugo caches processed images to reduce build time during subsequent builds. Disk space is cheap; processing time is not.

The best place to cache images depends on your deployment method. How will you deploy your site?

Usually, I deploy the complete sources for the site to the server and build on the server itself (thus the resources/_gen will be on the server). This theoretically allows me to update the site from anywhere, whether I have access to my main development machine or not. (i.e. push to a git repository).

I may need to rethink this strategy and consider a build locally and transfer approach instead.

If you push your source code to a Git repository and let the hosting platform build and deploy it, update the cache location:

[caches]
  [caches.images]
    dir = ':cacheDir/images'

This step is included in all of our guides.

If you build locally and transfer the files to your host, the cache location is irrelevant.

In both cases, exclude the resources directory from source control.

Related: https://discourse.gohugo.io/t/updated-hosting-guides/57298