# Using the new \`cachebusters\` feature with a theme

**URL:** <https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700>\
**Category:** support\
**Created:** [June 5, 2023, 12:27pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700 "2023-06-05T12:27:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwintx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bwintx/32/10450_2.png) [@bwintx](https://discourse.gohugo.io/u/bwintx)\
**Post date:** [June 5, 2023, 12:27pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/1 "2023-06-05T12:27:14Z")

</div>

The example config in the [0.112.0 release notes](https://github.com/gohugoio/hugo/releases/tag/v0.112.0) and in the current version of the [Hugo/Tailwind starter](https://github.com/bep/hugo-starter-tailwind-basic) assumes a single CSS file located at the `assets/css/` level. However, if I use a theme and have multiple CSS files in `themes/[theme-name]/assets/css` instead, what change should I make in the `cachebusters` setting for the CSS files?

The Hugo dev server’s `--debug` mode reports no `cachebusters` matches when I edit a template while using the following:

```auto
[[build.cachebusters]]
  source = "themes/[theme-name]/assets/css/watching/hugo_stats\\.json"
  target = "themes/[theme-name]/assets/css/.*\\.css"

```

(Or, in a `build.toml` file, that presumably would be `[[cachebusters]]`.)

I have found that the documented `cachebusters` setting works great for `assets/css/*.css`, but can’t seem to figure out how to adapt it for use in a theme-based directory structure. I also tried **not** putting the `themes/[theme-name]/` part in the `source` setting, but that failed, too.

_(These are uncommitted changes, due to other work I’m still doing in the repo; thus, there is no additional link I can provide at this time.)_

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [June 5, 2023, 3:08pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/2 "2023-06-05T15:08:19Z")

</div>

- Source will be relative to the component root even if it’s a theme – and it doesn’t matter where it’s mounted, so 'assets/css/foo.css` will be correct even if foo.css comes from a theme.
- Target is always starting from the root assets folder, e.g. css/, but I would recommend that you define it a little more coarse grained, e.g just `.*\\.css` or maybe even just `css` which is a valid regexp that will match “anything css”.

A general tip is to run the server with `hugo server --debug` and see the relevant debug lines when you change a given file.

---

<div class="post-metadata">

**Author:** ![bwintx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bwintx/32/10450_2.png) [@bwintx](https://discourse.gohugo.io/u/bwintx)\
**Post date:** [June 5, 2023, 3:52pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/3 "2023-06-05T15:52:11Z")

</div>

Thanks. Actually, I was already using `--debug`, as I noted. Have tried all of these combinations and I get `no match` with each when changing an `.html` template file:

```auto
  source = "themes/twcss/assets/css/watching/hugo_stats\\.json"
  target = "css"

```

```auto
  source = "assets/css/watching/hugo_stats\\.json"
  target = "css"

```

```auto
  source = "assets/css/hugo_stats\\.json"
  target = "css"

```

```auto
  source = "hugo_stats\\.json"
  target = "css"

```

I should note that this is **not** with the `modules` settings used in the example, because this project is not using Hugo Modules. However, I did the same non-`modules` config with that other project I mentioned, for the same reason, and all worked fine — although, to repeat, that project **wasn’t** using a theme.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [June 5, 2023, 4:00pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/4 "2023-06-05T16:00:22Z")

</div>

> [@bwintx](#):
>
> get `no match` with each when changing an `.html` template file:

Just to be clear: The `source` is matching against the _file that’s changed_, the concept being

- When source assets/foo.js changes then cache bust all files matching target.

What’s missing in your setup above is the `build.writeStats = true`. What happens is this:

- You edit an html file
- Hugo builds
- hugo\_stats.json gets updated and we get a new build.
- Now your source matches your cache buster config

The above looks a little funky, but it actually works pretty nicely.

---

<div class="post-metadata">

**Author:** ![bwintx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bwintx/32/10450_2.png) [@bwintx](https://discourse.gohugo.io/u/bwintx)\
**Post date:** [June 5, 2023, 4:01pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/5 "2023-06-05T16:01:30Z")

</div>

Thanks! Will keep trying. I do have `writeStats = true` in my `build.toml`.

(Also: nice release on 0.113.0! Just saw that shortly ago.)

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [June 5, 2023, 4:08pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/6 "2023-06-05T16:08:56Z")

</div>

> [@bwintx](#):
>
> ```auto
> source = "assets/css/hugo_stats\\.json"
> target = "css"
> 
> ```

OK, what I suspect is missing from your setup is the mount for hugo\_stats.json, see:

> <https://github.com/bep/hugo-starter-tailwind-basic/blob/aff6bf77afecee184e36b2c74f689f64a6448c54/hugo.toml#L13>

That’s just a dummy mount added to make sure that it gets added to Hugo’s watch list – so when that file changes =\> new build.

---

<div class="post-metadata">

**Author:** ![bwintx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bwintx/32/10450_2.png) [@bwintx](https://discourse.gohugo.io/u/bwintx)\
**Post date:** [June 5, 2023, 4:13pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/7 "2023-06-05T16:13:10Z")

</div>

Yep, that was it. Guess I was just lucky with that other project. Thank you, sir!

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [June 7, 2023, 4:13pm UTC](https://discourse.gohugo.io/t/using-the-new-cachebusters-feature-with-a-theme/44700/8 "2023-06-07T16:13:58Z")

</div>

Closed on June 7, 2023, 4:13pm UTC

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