Is the new js.Build functionality cached?

Hi all! I am loving the JS build / bundling support; it makes it so easy to modify JS in themes, because you don’t need to go through the rigmarole of installing a full JS toolchain :sparkles:

I have one question to this feature – are the assets produced by calls to js.Build cached?

To make the question more concrete, I have a partial named head_includes.html:

{{ $opts := dict "targetPath" "js/main.js" "minify" true "target" "es2015" }}
{{ $mainJs := resources.Get "js/main.js" | js.Build $opts }}
<script type="text/javascript" src="{{ $mainJs.RelPermalink }}" defer></script>

This is included on every page on the site, and I wanted to make sure that the JS build is only running once per site build, rather than once per page.

Some limited profiling (with hugo --templateMetrics) and swapping between including this partial with both partial and partialCached results in no difference in build performance, which seems to suggest that the js.Build is cached, but I wanted to check :slight_smile:

1 Like

The short answer is YES.

The little bit longer answer is that we cache then entire pipe chain, example of such whould be:

{{ $mainJs := resources.Get "js/main.js" | js.Build $opts | minify | fingerprint }}

So you can safely include the above in a million pages, it will only be built once.


That’s exactly the information I was after; thank you! Would it be useful for me to submit a PR to the hugoDocs project with this info?

1 Like

PR 1184 submitted!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.