NOTES: Troubles Running/Linking Javascript in Hugo...
Last updated: Mar 11, 2020
Overrode theme’s head.html partial in order to add my own css and js files. Getting error on attempting to onload="start()” in baseof.html:
The resource from “http://localhost:1313/projects/js/titlescript.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).
It’d appear that the server is trying to load the script from the wrong directory. Changing the load directory in the <script> tag worked for titlescript.js but not scramble.js
Error claims that the script was blocked due to MIME type (“text/plain”) mismatch, but I’ve explicitly set type="application/javascript”…
Both load for blog home page, but not for any other page.
Noticed that scripts in theme have their own script.html partial which is called inside of baseof.html
tag. Copied script.html partial in order to override but got the same results.Also tried the defer <script> attrib.
Tried changing filepath again to reflect static directory. No dice.
Got script and web worker working as intended, but just for _index.md in the content directory. _index.md’s template is in the top of layouts directory and is called index.html. Surprise surprise.
Tried creating an about.html in the top of /layouts. Same error.
All pages work in Chromium… Maybe related to firefox rather than code?
Nope. The embarrassing conclusion: only needed to include ‘/’ after filepath.
Live and learn.