Replies: 1 comment
|
Patching Rough shape: // sw.js
self.addEventListener('fetch', (event) => {
const url = new URL(event.request.url)
if (url.origin === 'http://a-server.com') {
event.respondWith(
caches.match(event.request).then((cached) => cached || fetch(event.request))
)
}
})and populate the cache ahead of time from files you already have via the Filesystem plugin ( Two Capacitor-specific things to know before you go this route:
If your actual goal is simpler than a generic prefix rewrite, i.e. you always know upfront which specific bundled files should be served locally, precaching them in the service worker's |
Uh oh!
There was an error while loading. Please reload this page.
I would like to additionally patch fetch so that
fetch('http://a-server.com/this/path.js')first looks in the capacitor file system forcapacitor://localhost/this/path.jsand serves that if it exists, otherwise it hits the internet.How could I set that up?
All reactions