-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query Parameters on the registration URL #587
Comments
Hi @userquin! I've experimented with this locally and it appears to work as intended. I'd like to make a contribution for vite-plugin-pwa for query parameter support, and I'm wondering whether you (or another maintainer) have input towards what the API might/should look like? I envision an additional optional property in Please let me know your thoughts! |
I guess we should add it to custom injectManifest configuration option, this way we can inject the query params in the client and use it also on src/plugins/dev.ts plugin, check src/client/build/register.ts module and dev.ts plugin. Client injections can be found in src/modules.ts module. Line 6 in 4d3b1d0
|
If we add query params as a property to |
There should be only one source, if we add the option to the client side, dev will not work.
No, will work also in dev (when enabled), Anyway, I have no idea if the browser/workbox will interpret the url with params as a new sw, we need to ensure the sw is the same. EDIT: in any case, you can register the sw yourself without using |
@develohpanda |
Hi! Thank you for this wonderful plugin.
I'm working on something that would greatly benefit from being able to pass query parameters to the service worker registration URL. Something like,
/sw.js?version=1.0.3
. This way, within an incoming service worker I am able to donew URL(self.location).searchParams.get('version')
, and pass information to an incoming service worker during updates. (See SO answer)Example
One example of a use case would be that by sending a query parameter, I am able to convey to an incoming service worker information about the currently running application/service worker. Then, I can check whether the incoming service worker should force-install (via
self.skipWaiting()
and claim and refresh all clients in theactivate
event). I will be able to compare the version of the incoming service worker (let's say 2.0.0) with the current application (1.0.3 from the query parameter).This is useful because it allows the incoming service worker to determine independently it's installation behavior, and we don't need to rely on currently running code (from the assets served by the existing service worker) to do the force update. This is fairly critical to my use case and I'm exploring what options are available.
Alternative
Is there a way to send query parameters currently, that I am missing? I am using React, and there is not a way to use the
useRegisterSW()
utility hook to send query parameters, nor a way to set additional query parameters in theVitePWAOptions
.The text was updated successfully, but these errors were encountered: