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
- Add simple chunking:
node_modulesgoes tovendor- 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';
},
},
},
- Create initial build (lets call it "build V1")
dist/assets/index.SBYBNO79.jsdist/assets/vendor.b1e99d.js
Open up in iOS - everything works fine
- Make any kind of an update, rebuild (call it "build V2")
dist/assets/index.-9z7R_h8.js(updated)dist/assets/vendor.b1e99d.js(same)
- 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
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.



