It works when the List.js file is pulled in from the CDN URL. However when I comment that out and un-comment the code to use the local List.js instead, it doesn’t work…
What am I doing wrong in trying to use a local JS file instead of an external one?
Why would that be me? I find the docs very helpful - they’re what have helped me understand and learn what I have so far to setup Hugo with the site I’m building.
Based on @davidsneighbour’s post above I learnt to just reference the JS instead of using the build command(s). My subsequent questions have been around trying to understand what the build commands do…
When I was trying to use it, I didn’t specify any options (so was just using the defaults). This should have meant not trying to minify an already a minified file, so I’m not sure why it wasn’t working.
By “does not work” I meant that the JS wasn’t being included, so the search/filtering wasn’t working.
I think the conversation went a bit away from the whole topic
What happened in my opinion was that js.Build took something already
“prepared” and tried to prepare it again. Can’t make fried eggs from an omelette, so to say. The min in the file name indicates that all this optimisation was already done on the file. I think the min-less version of the CDN file would have no problems with js.Build.
The reason, in my opinion, is, that the min-file was already touched by esbuild, which would rename functions, replace variable names etc. instead of just removing whitespaces.
Long story short: use js.Build on UNPREPARED JavaScript code. I don’t think CDN files will work with that because (function of a CDN) they did all the preparing for you already and those files up there are for “dropping them in a script tag”.
You typically go to the original package location and create your file from src/. So either know what you do and use js.Build, or use a script tag and put it in and forget it. “Official” CDNs are there to make life easier for you and tend to be around stable enough, have cache headers that don’t make your site slower and minify more or less optimal.
The file to look at is layouts/baseof.html. As it is currently (running js.Build on list.js), it doesn’t work. But if you comment out lines 12-14 and uncomment line 11, then it does work…
As Me and @davidsneighbour stated that’s superfluous and the correct way to use a CDN file is: just use it as is.
To close the loop.
as I said it’s in the options you use the default setup.
Your test.js fails because it tries to create an object of type List. BUT you bundled the list.js to an IIFE which creates a self executing function and hides the List type inside. see format option