My builds are very erratic. When I run hugo serve
the builds take up from half a minute to nearly 1 and 1/2 minutes! Is image processing slowing the builds? (I am also unsure if it is my machine with 8GB of RAM).
Without looking at your entire project, we would have to guess.
It certainly has a cost. Remove those bits and test again.
I commonly run with 12 GB and have never noticed a problem.
Before and after test shows it is the image processing. Only the initial build is slow on my machine, but subsequent builds are faster. Is this code not supposed to cache () processed images to speed up builds?
[caches]
[caches.getresource]
dir = ':cacheDir/:project'
maxAge = "48h"
[caches.images]
dir = ':resourceDir/_gen'
maxAge = "48h"
[caches.assets]
dir = ':resourceDir/_gen'
maxAge = 48h"
Is there any problem in increasing the time for images? Like say, 168 hours (1 week)?
Do you check your resources directory into source control?
Where do you build your production site?
This is from the Hugo docs site…
.gitignore
/.idea
/.vscode
/public
/dist
node_modules
nohup.out
.DS_Store
trace.out
.hugo_build.lock
resources/_gen/images/
site config
[caches]
[caches.getjson]
dir = ":cacheDir/:project"
maxAge = -1
[caches.getcsv]
dir = ":cacheDir/:project"
maxAge = -1
[caches.images]
dir = ":cacheDir/images"
maxAge = "1440h"
[caches.assets]
dir = ":resourceDir/_gen"
maxAge = -1
The site is built on Netlify.
No. Because the Cloudflare Pages does not cache subsequent builds (their build image does not as of yet).
Cloudflare Pages. But I want to speed up local builds instead. Cloudflare builds are not going beyond 48 seconds, and Hugo being 4-8 seconds overall. So, production builds are fine.
Well, if you checked your resources directory into source control, they would use that cache given:
[caches.images]
dir = ':resourceDir/_gen'
maxAge = "48h"
How often do you change an image after you have added it to the project. I’m not asking if you change image processing options, I’m asking how often you change the underlying image.
If the answer is “rarely” then increase your cache maxAge.
They clean up the server and re-install everything afresh for every build.
Rarely, but I play around with image sizes a few times a week in the templates and the render hook, especially since I am still building the site.
I rechecked my templates and dropped a few unnecessary image sizes. Build time drops to 18 seconds as per hugo --templateMetrics --templateMetricsHints
. I will continue with farther testing.
This will create new files in the cache due to different filenames, so having a long cache time isn’t a problem.
Right, but they clone your project from GitHub on every build, so they would get the resources directory and wouldn’t have to rebuild the images. Trade off between imaqe processing time and time required to clone the repo.
I didn’t know this. I now removed the resources folder from gitignore
file.
@jmooring I guess my closing question was if the local server uses the cached resources or generates everything afresh?
Assuming you have an image cache config with a maxAge set to > 0, then yes.
Sweet! My previous mistake was not including the image caching in the configuration file. I have seen builds now taking no more than ten seconds.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.