Hugo: --minify does not work on the script tags in partials

Created on 6 Aug 2018  路  6Comments  路  Source: gohugoio/hugo

Example:

View the source of the above 2 HTML pages. The difference will be visually evident in the beginning of the HTML sources.

With external minification, the code in script tags gets minified too. The inline script is from this partial. The partial is included in single.html layout here.

My site uses strict CSP with hashes for inline scripts. As the inline script when using --minify did not get minified, I started getting CSP failure for that (functionally, the dynamic TOC works on that page for the external minified version, but not for the other).

It would be great if the inline script can get minified too. If not, I'd like to understand (for documentation) why it did not get minified..

  • because of the minify switches used by Hugo?
  • because that code is in script tags?
  • because that inline code is included by a (cached) partial?

Thanks!

Most helpful comment

I suggest you match the JS mime type by something similar as to what I use: m.AddRegexp(regexp.MustCompile("^(application|text)/(x-)?(java|ecma)script$"), jsMinifier), then you don't have to explicitly state application/javascript for every script.

For a full list see https://www.w3.org/TR/html5/semantics-scripting.html#scripting-languages

All 6 comments

That the internal minification is different than some external minification, should not come as a surprise.

As I said in the other thread, I'm not working any more short-term on this particular feature, but if you want to investigate, feel free.

That the internal minification is different

More than different.. just trying to understand why inline JS in script tags is not getting minified.

More than different.

Sure, but the statement is a little like "Hugo behaves differently from Jekyll".

See https://github.com/gohugoio/hugo/commit/755d1ffe7a22d8ad83485240ff78cf25d501602f

There may be ways to loosen up the matching here, but taking every "

Related issues

VoidingWarranties picture VoidingWarranties  路  3Comments

crash-dive picture crash-dive  路  3Comments

bep picture bep  路  3Comments

kaushalmodi picture kaushalmodi  路  3Comments

ianbrandt picture ianbrandt  路  3Comments