I have a website which has a service worker like:
// Import a script from another domain
importScripts('https://example.com/script.js')
Suppose that script.js
is updated with some new code and the service worker is activated due to a push event (the user is the meantime has not visited my website again).
Does importScripts
checks for updates each time the service worker is activated or it downloads the script.js
just once when the service worker is first installed?
Is there any way to have the service worker code (and in particular the imported scripts) refreshed each time the service worker receives a push message?
From the Service Workers specification, scripts imported via importScripts
are stored in a map when the Service Worker is installed/updated and are then reused until a new update. There's a discussion on GitHub with more details.
I can't think of a way to reload the imported scripts when a service worker receives a push message. What is your use case?