It is my understanding that a JS file should be put into /assets/js/file.js, because this way it can get minified and fingerprinted (https://gohugo.io/hugo-pipes/minification/).
I did so, my file is in /asses/js/file.js.
I’m using it in a partial like this:
{{ $js := resources.Get "js/klaro.js" }}
{{ $file := $js | resources.Minify }}
<script defer type="application/javascript" src="{{ $file | relURL }}"></script>
But the file can’t be found (404 error). Obviously I’m suspecting some issue with the path. That’s why I tried several other things:
- Using absURL instead of relURL
- Referencing the file without minification (
- Using the “assets/” prefix in the path examples above
- Putting the file into static/js/
Nothing of this worked, except when I put the JS file into static/img. Then this worked:
Can anybody tell me
- Why is the file found when being in /static/img, but not in /static/js?
- How do I correctly use a js file in /assets?
Maybe the config is relevant as well:
baseURL = "http://my-website"
Thanks a lot!