JS library breaks when minified

I am working on a project, and it uses a library called list.js, which is used to perform search operations. I am trying to use Hugo’s asset pipeline to minify (unminified) list.js, but turns out that it is breaking the library(code, artifacts here (includes public/). I have linked the list.js file in this file (it’s slightly complex setup :slightly_smiling_face:). Thoughts?

Note: As Hugo was breaking the library after minification, I am currently using minified version of list.js shipped from official website (without Hugo’s minify). See live website here.

Your last sentence points to the solution. You are using the already minified version and minify it again. Don’t. If you let Hugo do the minifying then use the un-minified original.

1 Like

Oops! My question was not clear. Sorry. I meant that I have tried to minify unminified version, but as it was getting broken, I am now using minified version of the library (and not applying the Hugo’s minify). I have updated the question. :smile:

Have a look at my (too long) script production:


{{ $js0 := resources.Get "js/libs/jquery.js" }}
{{ $js1 := resources.Get "js/libs/popper.js" }}
{{ $js2 := resources.Get "js/libs/bootstrap.js" }}
{{ $js32 := resources.Get "js/libs/de.js" }}
{{ $js31 := resources.Get "js/libs/moment.js" }}
{{ $js4 := resources.Get "js/libs/instantsearch.js" }}
{{ $js5 := resources.Get "js/youtube-embedder.js" }}
{{ $js6 := resources.Get "js/soundcloud.js" }}
{{ $js7 := resources.Get "js/progress-indicator.js" }}
{{ $js8 := resources.Get "js/search.js" }}
{{ $js9 := resources.Get "js/script.js" }}
{{ $js10 := resources.Get "js/cookieconsent.min.js" }}
{{ $js := slice $js0 $js31 $js4 $js5 $js6 $js7 $js8 $js9 $js10 | resources.Concat "script.js" | resources.Minify | resources.Fingerprint "sha384" }}

I first get all scripts together and THEN minify.

I think in your script the list.js gets minified, then the commands and variables are basically changed by the minification algorithmus, so when your local script calls the list.js script it’s not there anymore.

If you concatenate all the files (first libraries, then calls to the libraries) and then minify the whole thing as one file, it should help.

If that does not help you will need to provide the errors that come up in the browser console when the list.js file is broken. or even the full repo.

@davidsneighbour Thank you for your help.

I had mistakenly added an HTML comment in the block that I had included in script tag in baseof file. That comment was leading to error, and it was nothing to do with Hugo’s asset pipeline. Still wondering why that comment was left as is though. :thinking: