Hugo build caching
Is there a way to get build caching in Hugo sites? (cc @Dario , who seems to be the resident build cache maven)
19 Replies
Yes, I can impelement that π
Since I need to do it for docusaurus I might as well just do it for Hugo too π
but I have zero Hugo knowledge I'd like to get someone from the Hugo team ideally confirm what directories need to be cached
are you by any chance a Hugo maintainer and/or can you connect me with one? π
Oh fantastic! I am not a maintainer but I can reach out to one to let them know you're interested in working on this.
the cacheDir is configurable. I think that's all you'd need to support: https://gohugo.io/getting-started/configuration/#configure-cachedir
Configure Hugo
How to configure your Hugo site.
Thank you very much for looking into this!
By default, we create a "hugo_cache" directory in the user cache directory as determined by https://pkg.go.dev/os#UserCacheDir. For example, by default, on Linux my cache directory is /home/jmooring/.cache/hugo_cache. Although users can override the location of the cache directory, that's not something you need to worry about... it would be a self inflicted wound in this context.
By default, this directory contains cached modules and remote data. Users can configure a site to cache images in this location as well. This is a big win for sites that perform image processing. See https://gohugo.io/getting-started/configuration/#configure-file-caches.
Configure Hugo
How to configure your Hugo site.
GitHub
hugo/helpers/path.go at 7f3061723e3df064515fc57c183b06ed16f26b75 Β· ...
The worldβs fastest framework for building websites. - gohugoio/hugo
Dario, @jmooring is on the Hugo team and would be an excellent resource if you have any questions! Thanks again, both of you!
I'm sorry I completely missed the replies is thread! π (I feel like discord's notifications aren't always the most helpful! π
)
our build cache implementation is unfortunately a bit limited and it doesn't really implements any integration with possible framework customization, so it always only checks the default directory (/directories)
fortunately it seems like you're ok with that ππ
https://github.com/gohugoio/hugo/blob/7f3061723e3df064515fc57c183b06ed16f26b75/helpers/path.go#L374
regarding the netlify=true... I need to check I am not 100% sure if that applies to the v2 build image π€
GitHub
hugo/helpers/path.go at 7f3061723e3df064515fc57c183b06ed16f26b75 Β· ...
The worldβs fastest framework for building websites. - gohugoio/hugo
I'll have to check about the dir location... as I said it's just static/hardcoded on our end, so I am not 100% sure if
UserCacheDir
will always be the same for every single build...
if it's not this could require a bit of refactoring on our end (with some potential pushbacks).
Or maybe you'd be willing to add an additional ad-hoc if
check for Cloudflare like you did here: https://github.com/gohugoio/hugo/blob/7f3061723e3df064515fc57c183b06ed16f26b75/helpers/path.go#L373-L381GitHub
hugo/helpers/path.go at 7f3061723e3df064515fc57c183b06ed16f26b75 Β· ...
The worldβs fastest framework for building websites. - gohugoio/hugo
@jmooring (or @tmcltr) could you let me know the simplest/dumbest way in which I can check if the caching is taking place? does hugo provide logs in its build command? and does the caching always kicks in?
sorry before I forget, thanks for connecting us! β€οΈ
@Dario I'm not receiving email notifications, so feel free to reach me via email [email protected]. "Or maybe you'd be willing to add an additional ad-hoc if check" -- yes, I think that would be fine. "netlify=true" I hope that's not true anymore.
Would that cover resized images as well? (I'm not committing
resources/_gen
to the repo)Does anyone have a status update on this? @Dario @jmooring
Hey @tmcltr so sorry this completely went off my radar π
I did start look into it but there's a non trivial issue with enabling build caching with Hugo π
the fact that hugo is not node/npm based and all our build caching code is npm-based, so to support hugo we'd have to add a separate build cache implementation from scratch for it π
not impossible but it'd take some effort for sure (and I don't really have lots of time at the moment, I can make a note of this and get back to it as soon as I can if it can help π, or I can ping the team which own that infrastructure but I can't imagine this getting prioritized unfortunately π)
Ah ok, understood! Thanks for looking into it anyway.
I was hoping there'd be at least some appetite to make this happen, since y'all appear to be using Hugo and Pages for the your own developer docs: https://blog.cloudflare.com/new-dev-docs/
The Cloudflare Blog
We rebuilt Cloudflare's developer documentation - here's what we le...
In this blog post, weβll cover the history of Cloudflareβs developer docs, why we made this recent transition, and why we continue to dogfood Cloudflareβs products as we develop applications internally.
Looks like @Kristian worked on that post, so maybe he knows if that's still the case?