Does CSS get recompiled / reminified every time a page is created?

I am creating a new theme and put together a CSS asset pipeline for my sass like so:

	{{ $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "main.scss" . | toCSS (dict "targetPath" "assets/css/main.css" "enableSourceMap" false) }}
	<link rel="stylesheet" href="{{ ($style | minify).RelPermalink }}">

Everything works fine on my home page, but I’m not sure what happens as I start adding posts (singles) to the website.

If I put an asset pipeline into baseof.html or a head partial that gets included everywhere, does the pipeline get re-executed (and hence the CSS get re-compiled / re-minified) for every page on the website?

Should I be trying to find a way to make sure that the pipeline only gets executed once?

I’m sure there’s a best-practice, I just don’t know what it is.


Is this a “best practices” question, or are you running into an issue?

Best practices, but I don’t want to paint myself into a corner since the site will eventually have about 5,000 pages on it.

Best practice is to load a stylesheet resources in the head of a document, so when you change the one file, all the others still reference it by URI, but they don’t have to be updated.

When you update CSS for a website with 5000 pages, it should not affect those pages; changes gets rendered in the browser when a visitor loads your web resource.

There is a chance you are loading inline CSS inside each page, and if so, don’t. :sunglasses:

What brought this to mind? If you aren’t affected adversely, what indicates this will be an issue for you in the future? Are you getting longer build times?

No, once only.

Sorry – I meant hugo best-practice. I understand how the CSS works when it’s deployed, my concern was related to any unexpected / unpredictable issues that may come up calling that asset pipeline over and over again thousands of times.

I’m trying to avoid rando calls at 2AM from someone telling me that my build scripts broke and I need to fix it :smile:


I had the same concerns when I implemented it. Doing SCSS/SASS or even worse PostCSS transformations tens of thousands of times would … not scale. 10000x1s is … 3 hours?

1 Like

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