Hybrid Workspace

Operations

Why your Shopify app still runs old JavaScript after a deploy

You deploy, the Shopify admin keeps running yesterday's app until someone clears their browser. Why it happens, how to confirm it in a minute, and the fix.

· 5 min read

You deploy a fix to your app's front end. In the Shopify admin, the app still behaves as it did yesterday. It updates for you after you clear your browser data, so you tell yourself it is fixed. Your merchants never clear anything, so for them it isn't.

The cause is almost never Shopify, the iframe or cookies. It is two settings that are each reasonable on their own: a long cache lifetime on your static files, and a script URL that never changes.

Why it happens

Browsers keep a copy of every file a server says they may keep. When your server sends your bundle with a long lifetime, for example

Cache-Control: max-age=315360000
Expires: Thu, 31 Dec 2037 23:55:55 GMT

the browser is allowed to use its copy for years without asking again. If your page then loads the bundle from the same address after every deploy,

<script src="/js/app.js"></script>

nothing tells the browser the file changed. It keeps running the copy it has. Clearing browser data "fixes" it only because it throws that copy away.

Long cache lifetimes are common defaults: many server panels and hosting setups add them to .js and .css files. So the first deploy after you switch hosts is often when this starts.

Confirm it in a minute

Ask your server for the bundle's headers:

curl -sI https://your-app.example.com/js/app.js | grep -iE "HTTP|cache-control|expires"

It is this problem when both are true:

  • the answer has a long max-age or an Expires date far in the future;
  • the page's script tag has the same address before and after a deploy, with no version in it.

Inside the Shopify admin the app runs in an iframe: in the browser's developer tools, pick the app's frame to see its HTML and the script address it loads.

The fix: change the address, keep the cache

Don't shorten the cache. A long lifetime is what makes your app load instantly on the second visit. Make the address change whenever the file does instead, so a new deploy is a new file to the browser. web.dev calls these versioned URLs; build tools call it fingerprinting or cache busting.

If your bundler names files by content

Vite and webpack can put a hash of the content in the file name (app.3f9c1b.js), and write a manifest your server uses to find the current name. If your bundler already does this and your pages read the manifest, you are done; check that the manifest is deployed with the bundle every time.

If the file name never changes

Add a version to the address yourself. The simplest version is the file's modification time on the server, which changes on every upload or rebuild. In PHP:

<script src="/js/app.js?v=<?= @filemtime(__DIR__ . '/js/app.js') ?>"></script>

In a Laravel Blade view:

<script src="{{ asset('js/app.js') }}?v={{ @filemtime(public_path('js/app.js')) }}"></script>

Do the same for the stylesheet and for any other file your pages load that changes between deploys. The @ means a missing file gives an empty version instead of an error page.

If you use Laravel Mix, mix.version() and {{ mix('js/app.js') }} do the same with a content hash, as long as mix-manifest.json is deployed with the bundle every time. The modification time needs no manifest at all.

Find every place the file is loaded

Apps with several pages often load the bundle from several templates. Search for every one:

grep -rn "app\.js\|app\.css" resources/views

A template you miss keeps serving the old code on that page, which looks like a random bug.

What not to do

  • Don't send no-cache for the bundle. Every page load then downloads it again, and the app gets slower for everyone.
  • Don't ask merchants to clear their cache. The ones who don't, which is nearly all of them, keep the old version.
  • Don't confuse it with files Shopify serves. The files in a theme app extension's assets folder are served by Shopify, not by your server. This problem, and this fix, are about files your own server serves.

After the fix

  • Look at the page source: the script address ends in ?v= and a number (or carries a hash).
  • Deploy again and reload: the number changes, and the new code runs without clearing anything.
  • Someone who had the app open during the deploy still has the old version until their next page load. That is expected.

A use case: a fix that "only worked after clearing the cache"

Our cash on delivery app's admin pages are Blade views that each load one compiled React bundle. Deploys stopped reaching anyone: the server sent .js files with a ten-year max-age and an Expires date in 2037, and every view loaded js/app.js with no version. Clearing browser data was the only way to see a change.

The fix was the ?v={{ @filemtime(...) }} line in every view that loaded the bundle or the stylesheet, and nothing on the server: the long cache stayed, because now it only ever caches the current version. We wrote the steps down so the same fix takes minutes the next time it shows up, on any app served the same way.

If you look after several apps, Hybrid Workspace keeps them on one screen. For the platform changes every app has to make this winter, see Shopify app security deadlines 2026–2027.

Sources

  • shopify apps
  • embedded app
  • caching
  • cache busting
  • deploy
  • javascript