Can you call minify in template for css AND using config minify.output?

I’m wondering if it’s ok, or what to expect if one:

  1. Calls the minify function on css and then fingerprints it and then outputs it to a file
  2. And also has in the config.toml the [[minify.minifyOutput]] = true

What will happen to the references to the fingerprinted css file? or will it ignore since minify was already called on it? Or do you remove the call to minify in the template and just rely on the config parameter? But how does that affect the fingerprinting and filename and link reference?

To minify an external CSS:

{{ $style := resources.Get "assets/css/style.css" 
    | minify  
    | fingerprint }}
<link rel="stylesheet" href="{{ $style.RelPermalink }}">

The fingerprint filter comes after the minify filter.

Setting minify.minifyOutput to true in your site configuration, or running hugo with the --minify option, will run the minifier on the HTML pages rendered to the publishDir. With the default configuration, the HTML markup will be minified, as will inline CSS, inline JS, etc.

This operation is independent of CSS/JS asset minification.

1 Like

Ok, so the --minify or config version of it will only minify the produced HTML and anything contained within. It will not touch any external resource files? So I can build an external css with a template and minify it in the process AND run the --minify option and it won’t affect the external css file or references within the html to it?

Correct.

Correct.

I’m not sure what you mean by this. Perhaps you should experiment to get a better understanding of how this works.

References to minified resources (e.g., link and script elements) will themselves be minified. For example:

<link rel="stylesheet" href="/main.min.css">

will be minified to:

<link rel=stylesheet href=/main.min.css>