-
Notifications
You must be signed in to change notification settings - Fork 312
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
Proposal: pass custom params in ServiceWorkerRegistration for future use #1157
Comments
Your example parameters seem like data that should be inlined into the body of your sw.js script or its dependencies (once #839 is implemented in all browsers so that changes to dependencies can trigger updates). This avoids introducing a de facto new storage API and provides clear semantics around ServiceWorker updates. (It's also a win/win from a browser engine and SW author perspective because there's no extra moving parts that could delay SW startup.) Note that your script URL can be something like |
@asutherland, I prefer not to change a file name, it will cause additional download for |
@laukstein Can you elaborate on your use-case, particularly in how it would work in terms of updates? It's not clear to me whether you want to use the parameters to avoid having to include, for example, https://github.com/GoogleChrome/sw-toolbox configuration in the SW script itself. Or if the parameter would be something higher level, such as picking which branch/release of an app to use (such as is discussed in #1085). Also of relevance is how you would plan to detect and correct ServiceWorkers stuck with a bad parameter configuration. Aside: If you're concerned about additional downloads of sw.js, you may also want to consider using useCache=true and ensuring your server has appropriate cache settings, because SW's really like to do update checks. If things aren't well-cached then the script and all its dependencies could be re-downloaded so that the byte-wise comparison check can be performed. |
@asutherland my question isn't related spec issue, and not #1085. I want to pass whatever params to sw.js without adding params in URL. Imagine like HTML having multiple JS files with global variables - each of the files can after read those global variables, while in sw.js it is not allowed, even will not access localStorage ... I want be able to define whatever params in |
Why isn't indexeddb the solution here? |
@jakearchibald serviceWorker works also in private browsing (incognito window), while IndexedDB doesn't not in Firefox (similar with localStorage in Safari). Another issue, I wouldn't want serviceWorker to wait for async IndexedDB response to get |
This is a common mistake in standards discussion (and don't worry about it, it's a mistake I've made many times before). You cannot compare the current state of things, beholden to reality, with a utopian implementation of some currently non-existent thing. While IndexedDB may not currently work in Firefox when in incognito mode, your
Do you have data on the performance issue here? It could be something that's fixable. If looking up data is inherently slow, your |
@jakearchibald why not simply allow pass custom params (whatever) like Imagine array with In my case I am stuck with |
The addition of new features needs to be justified. It's more "why" than "why not" (see burden of proof). I haven't considered security issues with your proposal, but there's no point in adding it if we already have a feature that achieves roughly the same thing, and more.
Are you sure this is bad for performance? If you're using this as part of an installing worker it isn't blocking anything, and any performance penalty is surely minuscule compared to the network activity.
Can you explain why this would perform worse than your proposal? |
it will require addition async call before get to ServiceWorker events.
All this could be avoided with simple support by spec as proposed above. |
@laukstein you need to compare like-for-like here. In your proposal the browser is doing the work for you, but that doesn't mean it takes 0ms.
Right, but in your proposal
This isn't a browser problem, it's a problem you're creating yourself.
Whooaaaa how much data are you needing to pass in? If it's that much, the synchronous deserialising of that data is likely to be slooowww.
Right, but in your solution the data needs to be structured-clonable and deserialised per service worker startup. Just because the browser is doing it for you, doesn't make it free. For comparison's sake, here's what I'm proposing (using idb-keyval), which works today: In your page: async function registerSw() {
await idbKeyval.set('urlsToCache', ['/', '/cat.gif']);
return navigator.serviceWorker.register('/sw.js');
} In your service worker: addEventListener('install', event => {
event.waitUntil(async function() {
const [cache, urls] = await Promise.all([
caches.open('static-v1'),
idbKeyval.get('urlsToCache')
]);
await cache.addAll(urls);
}());
}); |
FWIW, service workers also don't work in private browsing mode in Firefox. |
Is there any spec - if anything expected to differ on private browsing? Or all that considered as browsers bugs and lack of support? |
I don't think private browser stuff is spec'd. We have some work in progress to make IDB work in private browsing mode. Its unclear if we will enable service workers there, though. |
Closing this. I wish we could just spec async localstorage, but I guess once you add something to handle concurrency issues, you're right back at IDB. |
Current spec https://w3c.github.io/ServiceWorker/#navigator-service-worker-register
I want be able to pass custom parameters to ServiceWorker for future use, since localStorage and sessionStorage aren't allowed. It would be grate be able to defined version, URLs to cache, etc. early in
navigator.serviceWorker.register
like:and after in sw.js use like:
Any early proposal for it? Any reason why not to implement this?
The text was updated successfully, but these errors were encountered: