How can I force client to not cache the svelte/rollup bundle.js?

Viewed 1881

My svelte rollup.js setup has an index.html file with this head:

    <link rel='stylesheet' href='/build/bundle.css'><!-- svelte -->
    <link rel="stylesheet" href="/build/index.css" /><!-- tailwind -->
    <script defer src='/build/bundle.js'></script>

When I deploy a new version to my web server, some clients don't fetch the new bundle.js but instead use their cached copy. What's a good way of forcing them to fetch the new bundle when I've deployed a new version?

The simplest way I can think of would be to add the version number or git commit hash to the end of src, e.g:

    <link rel='stylesheet' href='/build/bundle.css?v0.1.4'><!-- svelte -->
    <link rel="stylesheet" href="/build/index.css?v0.1.4" /><!-- tailwind -->
    <script defer src='/build/bundle.js?v0.1.4'></script>

But I assume this is a common problem, so I'd rather ask.

1 Answers
Related