iOS Safari loads outdated javascript

73 Views Asked by At

Problem

Safari on iOS tries to load memory-cached javascript that does not exist in HTML

On clean run - everything works fine. After publishing any update - Safari loads all the new files + old cached that is not referenced anywhere

Context

React app, Vite as a bundler.
Without "chunking" everything works fine. With "chunking" everything works everywhere except Safari iOS

Steps to reproduce

  1. Add simple chunking:
  • node_modules goes to vendor
  • everything else goes to index
rollupOptions: {
    output: {
        entryFileNames: 'assets/[name].[hash].js',
        manualChunks: (id: string) => {
            if (id.includes('node_modules')) {
                return 'vendor';
            } else {
                return 'bundle';
            }
        },
        chunkFileNames: (chunkInfo) => {
            const hash = createHash('md5')
                .update(Object.values(chunkInfo.moduleIds).join())
                .digest('hex')
                .substr(0, 6);
            return 'assets/[name].' + hash + '.js';
        },
    },
},
  1. Create initial build (lets call it "build V1")
  • dist/assets/index.SBYBNO79.js
  • dist/assets/vendor.b1e99d.js

enter image description here

Open up in iOS - everything works fine

  1. Make any kind of an update, rebuild (call it "build V2")
  • dist/assets/index.-9z7R_h8.js (updated)
  • dist/assets/vendor.b1e99d.js (same)

enter image description here

  1. Now when iOS Safari loads webapp - it fetches all the new stuff from new HTML

But it also loads old index.SBYBNO79.js, while there is no mention of it in the HTML

enter image description here

enter image description here

Thoughts

I wouldn't be bothered by it too much, but it crashes the app as it is out of sync with vendor bundle.

One of the options might be - to disable caching completely. But this is the point - I want to have javascript that is referenced from HTML to be cached.

Happens only on iOS Safari (mobile phone)

I tried to debug it for already 2 weeks, googled everything. Managed to narrow it down to this "extra" javascript request.

Would appreciate a lot any hint/direction.

0

There are 0 best solutions below