When I’m using Hugo Server and I add JavaScript to my page in any other way that the raw script inside a <script> tag, the server does not update the scripts on file change. It will notice that the file has changed and rebuild. But it does not fetch an updated version of the file.
Is this a browser setting or a server setting I need to change?
I have the same issue, and it persists after disabling cache in developer tools, both in Chrome and in Firefox. i have also quit and restarted my code editor and run hugo server with various options.
hugo version
hugo v0.128.0+extended darwin/amd64 BuildDate=2024-06-25T16:15:48Z VendorInfo=brew
@kayesspea can I ask how you build your JS? If with js.Build (the hugo template func, see js.Build | Hugo), are you setting a non-default format?
I have “never” had any issues with the default (iife), but I have been testing out esm for some upcoming code splitting feature, and I have seen some browser caching issues.
Also, could you try to add a $js | fingerprint and see if that forces a browser refresh of the script?
So I’m looking for a solution that lets me do a combination of #2 and #4. That way I can include and exclude things based on parameters as well as any page-specific scripts. I’m not sure where this behavior is coming from. But I only started doing #4 because I couldn’t just do #2
I’ve done a bit more poking around and found that scripts will update only if some markup is changed on the page. It can be as simple as adding a bit of whitespace. Perhaps this is why it is a very niche issue heretofore. Again, I’m not sure of where this behavior is coming from because I’ve been using Hugo for years and never encountered it before (or perhaps never noticed it before).
@kayesspea , thanks. I found that the issue for me was that after some unspecified amount of development, files in the assets folder ceased to be rendered at all. My workaround at present is to place my css and js folders in the static directory.
That makes sense. This is a “blog” that is really a set of min-apps that I export and use on my phone. I’ve been developing it for years so perhaps it’s a versioning issue