# Cache busting for updated scripts in theme components?

**URL:** https://meta.discourse.org/t/cache-busting-for-updated-scripts-in-theme-components/243036
**Category:** Development
**Created:** [October 27, 2022, 2:29am UTC](https://meta.discourse.org/t/cache-busting-for-updated-scripts-in-theme-components/243036 "2022-10-27T02:29:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rahim123](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@rahim123](https://meta.discourse.org/u/rahim123)
#### Post date: [October 27, 2022, 2:29am UTC](https://meta.discourse.org/t/cache-busting-for-updated-scripts-in-theme-components/243036/1 "2022-10-27T02:29:32Z")

</div>

Hi there, I was wondering what options might exist to make the cached Javascript in users’ browser sessions update when I change the image URLs and/or `<href>` links in this script, which is added as custom HTML in the **Head** section of a new theme component:

> [@How to use api.onPageChange with api.createWidget?](https://meta.discourse.org/t/how-to-use-api-onpagechange-with-api-createwidget/242744/4):
>
> Brilliant! Thanks so much, I never would have figured that out! Here’s the complete Head code for the theme component: \<script type="text/discourse-plugin" version="0.8"\> const h = require("virtual-dom").h; api.createWidget("top-banner-widget", { tagName: "div.top-banner", html() { let Number = Math.round(1 \* Math.random()); let banners = new Array(); banners[0]="https://example.com/uploads/default/original/1X/9d9762a4129c78c478d14ff857c3bd1f2be0322a…

With this current widget code it requires a browser refresh for users to see the newly updated images or changed links. I assumed that this would update via some sort of AJAX method in browser caches, just like CSS changes are reflected immediately without a page reload, but that’s not the case with custom **Head** scripts.

I noticed that the Ad plugin for house ads somehow manages to force a refresh immediately after changing the HTML for the ad. For the House Ads plugin I found the following in `house-ads.js` when searching for the keyword `refresh` :

```plaintext
  @observes("refreshOnChange")
  refreshAd() {
    if (this.get("listLoading")) {
      return;
    }

    this.set("adHtml", this.chooseAdHtml());
  },

  didInsertElement() {
    this._super(...arguments);

    if (!this.get("showAd")) {
      return;
    }

    if (this.get("listLoading")) {
      return;
    }

    if (adIndex.topic_list_top === null) {
      // start at a random spot in the ad inventory
      Object.keys(adIndex).forEach((placement) => {
        const adNames = this.adsNamesForSlot(placement);
        adIndex[placement] = Math.floor(Math.random() * adNames.length);
      });
    }

    this.refreshAd();
  },

```

Would a similar method somehow be applicable for my custom plugin Javascript?
