# How to use updated JavaScript minification?

**URL:** <https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968>\
**Category:** support\
**Created:** [October 22, 2020, 5:45am UTC](https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968 "2020-10-22T05:45:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jura](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jura/32/13581_2.png) [@Jura](https://discourse.gohugo.io/u/Jura)\
**Post date:** [October 22, 2020, 5:45am UTC](https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968/1 "2020-10-22T05:45:47Z")

</div>

[Hugo 0.76](https://gohugo.io/news/0.76.0-relnotes/) introduced an update to the `github.com/tdewolff/minify/v2` dependency that now has full support for JavaScript minification (that was added in [v2.9.0](https://github.com/tdewolff/minify/releases/tag/v2.9.0)).

But how do I use that updated JavaScript minifier?

`hugo --minify` on version 0.75.1 turns a piece of JavaScript into:

> var \_self=(typeof window!==‘undefined’)?window:((typeof WorkerGlobalScope!==‘undefined’&&self instanceof WorkerGlobalScope)?self:{});var Prism=(function(\_self){var lang=/\blang(?:uage)?-([\w-]+)\b/i;var uniqueId=0;var \_={manual:\_self.Prism&&\_self.Prism.manual,disableWorkerMessageHandler:\_self.Prism&&\_self.Prism.disableWorkerMessageHandler,util:{encode:function encode(tokens){if(tokens instanceof Token){return new Token(tokens.type,encode(tokens.content),tokens.alias);}else if(Array.isArray(tokens)){return tokens.map(encode);}else{return tokens.replace(/&/g,‘&’).replace(/\</g,‘\<’).replace(/\u00a0/g,’ ‘);}},type:function(o){return Object.prototype.toString.call(o).slice(8,-1);},objId:function(obj){if(!obj[’\_\_id’]){Object.defineProperty(obj,‘\_\_id’,{value:++uniqueId});}

`hugo --minify` on version 0.76.5 turns that same JavaScript into:

> var \_self=(typeof window!==‘undefined’)?window:((typeof WorkerGlobalScope!==‘undefined’&&self instanceof WorkerGlobalScope)?self:{});var Prism=(function(\_self){var lang=/\blang(?:uage)?-([\w-]+)\b/i;var uniqueId=0;var \_={manual:\_self.Prism&&\_self.Prism.manual,disableWorkerMessageHandler:\_self.Prism&&\_self.Prism.disableWorkerMessageHandler,util:{encode:function encode(tokens){if(tokens instanceof Token){return new Token(tokens.type,encode(tokens.content),tokens.alias);}else if(Array.isArray(tokens)){return tokens.map(encode);}else{return tokens.replace(/&/g,‘&’).replace(/\</g,‘\<’).replace(/\u00a0/g,’ ‘);}},type:function(o){return Object.prototype.toString.call(o).slice(8,-1);},objId:function(obj){if(!obj[’\_\_id’]){Object.defineProperty(obj,‘\_\_id’,{value:++uniqueId});}

This output is completely identical, with no JavaScript minification benefits.

But if I copy/paste my JavaScript into Taco’s [online minifier](https://go.tacodewolff.nl/minify) (which is what Hugo uses behind the scenes), I get:

> var \_self=typeof window!=‘undefined’?window:typeof WorkerGlobalScope!=‘undefined’&&self instanceof WorkerGlobalScope?self:{},Prism=function(b){var i=/\blang(?:uage)?-([\w-]+)\b/i,l=0,a={manual:b.Prism&&b.Prism.manual,disableWorkerMessageHandler:b.Prism&&b.Prism.disableWorkerMessageHandler,util:{encode:function b(a){return a instanceof c?new c(a.type,b(a.content),a.alias):Array.isArray(a)?a.map(b):a.replace(/&/g,‘&’).replace(/\</g,‘\<’).replace(/\u00a0/g,’ ‘)},type:function(a){return Object.prototype.toString.call(a).slice(8,-1)},objId:function(a){return a.\_\_id||Object.defineProperty(a,’\_\_id’,{value:++l}),a.\_\_id},

This time my JavaScript is aggressively minified with all kinds of tricks to make the code smaller. How do I get this behaviour in Hugo?

(I have no configuration options set related to minification. Is there perhaps one I need to enable? I couldn’t find it in [the minify config](https://gohugo.io/getting-started/configuration/#configure-minify)).

* * *

```auto
> hugo env
Hugo Static Site Generator v0.76.5/extended windows/amd64 BuildDate: unknown
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.15.1"

```

---

<div class="post-metadata">

**Author:** ![Hrishikesh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hrishikesh/32/19176_2.png) [@Hrishikesh](https://discourse.gohugo.io/u/Hrishikesh)\
**Post date:** [October 22, 2020, 7:56am UTC](https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968/2 "2020-10-22T07:56:06Z")

</div>

The updated minification was introduced in 0.76.0, but, was reverted back to the previous one in 0.76.3 because it was breaking a few websites. Read here: [0.76.0 breaks lazy loading on my website](https://discourse.gohugo.io/t/0-76-0-breaks-lazy-loading-on-my-website/28696)

If you want to use it, you can use 0.76.0, 0.76.1 or 0.76.2.

---

<div class="post-metadata">

**Author:** ![Jura](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jura/32/13581_2.png) [@Jura](https://discourse.gohugo.io/u/Jura)\
**Post date:** [October 22, 2020, 8:26am UTC](https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968/3 "2020-10-22T08:26:41Z")

</div>

Thanks for your reply. That explains a lot.

Do you know what the path forward is? Because improved JavaScript minification is more than welcome in Hugo.

I see that the bug you reported couldn’t be reproduced by the developers, but I see that there are also 4 JavaScript minifier bugs fixed in the meantime.

---

<div class="post-metadata">

**Author:** ![Hrishikesh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hrishikesh/32/19176_2.png) [@Hrishikesh](https://discourse.gohugo.io/u/Hrishikesh)\
**Post date:** [October 22, 2020, 8:48am UTC](https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968/4 "2020-10-22T08:48:12Z")

</div>

> [@Jura](#):
>
> Do you know what the path forward is?

Unfortunately, I’m not the one who can answer that.

> [@Jura](#):
>
> Because improved JavaScript minification is more than welcome in Hugo.

I had felt so too, read here: [Is obfuscation of JavaScript possible in Hugo?](https://discourse.gohugo.io/t/is-obfuscation-of-javascript-possible-in-hugo/28675)

> [@Jura](#):
>
> I see that the bug you reported couldn’t be reproduced by the developers

It was reproduced as you can see in the last answer of the previous link. If it was an error on my end, it probably wouldn’t have been reverted.

---

<div class="post-metadata">

**Author:** ![Jura](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jura/32/13581_2.png) [@Jura](https://discourse.gohugo.io/u/Jura)\
**Post date:** [October 22, 2020, 9:51am UTC](https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968/5 "2020-10-22T09:51:46Z")

</div>

> [@Hrishikesh](#):
>
> It was reproduced as you can see in the last answer of the previous link. If it was an error on my end, it probably wouldn’t have been reverted.

It was not reproduced by Taco, the minifier developer, and that is what’s needed to fix minifier issues unfortunately.

I wasn’t implying that there was a mistake on your end. I simply said that some JavaScript minifications errors were fixed since then, so the minifier might work better now.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [October 24, 2020, 9:51am UTC](https://discourse.gohugo.io/t/how-to-use-updated-javascript-minification/28968/6 "2020-10-24T09:51:50Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
