Shouldn't changes to paths used with `readFile` trigger a rebuild?

Shouldn’t a rebuild be triggered if a file being used with readFile is changed and the change is detected?

What I was trying to do:
I was using resources.FromString to read static/custom.css and fingerprint it for cache busting. However, even when the CSS file was changed, the pages weren’t rebuilt and the changed did not reflect in the browser.

I am aware that this is not the ideal way to go about it and I have since patched the theme to treat the custom CSS file as a resource under assets/.

However, I wanted to know if this is the desired readFile behaviour. Of course changes in the static directory shouldn’t trigger a rebuild, but could there be an exception for paths used with readFile?

Maybe they should, but they don’t.

There’s a long story here, and I will soonish release a version with a much improved story of this, but for now this works pretty good if you:

  • Put (or mount) all of your CSS files below /assets/css
  • Put (or mount) all of your JS files below /assets/js (etc.)
  • Load them with resources.Get.

Also, I highly recommend that you enable fingerprinting (for cache busting) in production only (add a if hugo.IsProduction conditional in the template).

1 Like

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