Use electron with service worker to save/pre-load remote content

#1

I built an offline electron app. Everything works fine, but I want to be able to able to push out updates to my app.

Currently, all resources are loaded locally. I want to load all JS/CSS/HTML files from a remote web server and use service worker to handle the caching. However, when I install a service worker it gets scoped to the folder of the packaged exe and is unable to intercept fetch request from remote hosts.

Using service worker I was able to pre-cache everything I needed from a web server but unable to serve them from the cache.

Has anyone done something similar and be willing to offer some help :slight_smile: .

0 Likes

#2

Did you find a solution to the question you asked about getting service workers running in an Electron app? I’ve been looking to get a PWA running within Electron myself and was wondering if there’s a good solution out there.

0 Likes

#3

The issue is that the service worker will only load cached content for web pages with the same base url, even when offline.

So if you are going to use a service worker caching for hosted content, you need include html that has the service worker embedded in it, not the shell electron app. Although this has some limitations, it makes development easier, because it enables testing the hosted content and service worker caching in a regular browser.

0 Likes