# Optimization Question: CSS

**URL:** <https://discourse.gohugo.io/t/optimization-question-css/37357>\
**Category:** support\
**Created:** [February 24, 2022, 8:21pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357 "2022-02-24T20:21:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [February 24, 2022, 8:21pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/1 "2022-02-24T20:21:58Z")

</div>

Trying to understand why this is happening in terms of performance with my Head file. I understand the impact on my single pages but not why the head which is just a text link would be so impacted.

```auto
 {{ $styles := resources.Get "css/main.css" }} 
    {{ $styles = $styles | resources.PostCSS (dict "inlineImports" true) }}
    {{ if hugo.IsProduction }}
      {{ $styles = $styles | minify }} 
    {{ end }}
    <link href="{{ $styles.Permalink }}" rel="stylesheet" />

```

Without the CSS Link tag being produced I get

 ![Screen Shot 2022-02-24 at 12.18.18 PM](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/8/6/860e013693001078dbe8ec32f6096b60dfa042bd.png)

With the CSS link tag uncommented I get  
 ![Screen Shot 2022-02-24 at 12.19.15 PM](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/9/f/9f4bd575dfa372c86e0f910784b62e0c6eeb6f5f.png)

Any thoughts?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [February 24, 2022, 8:38pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/2 "2022-02-24T20:38:37Z")

</div>

As always, it would be really helpful if we had something to work with.

---

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [February 24, 2022, 8:44pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/3 "2022-02-24T20:44:03Z")

</div>

I know 🙁 but production repos have NDA content

I might be able to throw a demo site together just to showcase the issue at hand but was hoping there would be a quick solution/answer as to why

```auto
{{/* <link href="{{ $styles.Permalink }}" rel="stylesheet" /> */}}

```

```auto
<link href="{{ $styles.Permalink }}" rel="stylesheet" />

```

would produce such drastic head duration differences. I recognize the Single.html will now be rendering styled content which makes sense but for just a change in href I could not for the life of me figure out why that would have such a drastic impact.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [February 24, 2022, 8:49pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/4 "2022-02-24T20:49:46Z")

</div>

When you invoke the `.RelPermalink`, `.Permalink`, or `.Publish` method on a resource, it is written to disk. Have you tried using `partialCached` instead of `partial`?

Without something to look at, I’m just guessing.

---

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [February 24, 2022, 8:54pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/5 "2022-02-24T20:54:00Z")

</div>

> [@jmooring](#):
>
> When you invoke the `.RelPermalink` , `.Permalink` , or `.Publish` method on a resource, it is written to disk. Have you tried using `partialCached` instead of `partial` ?
> 
> Without something to look at, I’m just guessing.

Yea I did {{ partialCached “head.html” . }} which should cache it by language is my understanding.

---

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [February 24, 2022, 8:55pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/6 "2022-02-24T20:55:16Z")

</div>

Ahh, so it is writing the tailwind css to disk every time the .RelPermalink is called which makes sense. Is there a way to do this once for the whole site then while still maintaining the rest of the head caching per language?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [February 24, 2022, 9:03pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/7 "2022-02-24T21:03:58Z")

</div>

Extract the CSS processing as a separate partial.

---

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [February 24, 2022, 9:32pm UTC](https://discourse.gohugo.io/t/optimization-question-css/37357/8 "2022-02-24T21:32:45Z")

</div>

Hmmm. The documentation on [Partial Caching](https://gohugo.io/functions/partialcached/) says

> **Note:** Each Site (or language) has its own `partialCached` cache, so each site will execute a partial once.

So I’m not sure if that will actually improve anything since each language head file is already cached only once per site. Unless there is a way to cache at a higher level than that, I may have to move the css outside the Hugo project to squeak out that performance it seems. However in thinking about it I am going to go test if I can set a boolean flag somehow and then detect if the css has been created for the default language and reference that on each head.

As always @jmooring, thank you for your stellar knowledge of the system. I have learned so much from you in the past few months.
