arrow_back
Back

Hugo asset pipes: CSS, Sass, JS concat, minify, and fingerprint

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Hugo asset pipes work on files under assets/ (not static/).

CSS

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

resources.Get is rooted at assets/. Writing .RelPermalink copies the processed file into public/.

Minify and fingerprint

{{ $css := resources.Get "css/style.css" | minify | fingerprint }}

You get a name like /css/style.min.<hash>.css that changes when the content changes (cache busting).

Sass

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

Split styles into _partial.scss and @import them into the main file.

For Tailwind-specific setup, see Tailwind with Hugo .

JavaScript

{{ $script := resources.Get "js/script.js" }}
{{ $script2 := resources.Get "js/script2.js" }}

{{ $libs := slice $script $script2 }}
{{ $js := $libs | resources.Concat "js/app.js" | minify | fingerprint }}
<script src="{{ $js.RelPermalink }}"></script>

resources.Concat merges a slice of resources into one output file.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Hugo images: static files, page bundles, Resize, and shortcodes

arrow_forward