8 ms·
Service Workers
- deleted 8y ago[deleted]
- sbr464 8y agoGreat write up. I’ve been exploring SWs recently to help with downloading and caching data in the background for faster UI. Question, I’d like to avoid doing large downloads or possibly cap the transfer rate to avoid any potential jank. Is there a best practice or is it possible to monitor the current browser interaction to determine how strategically best to pull data with a SW? Depending on what a user chooses to cache, it’s JSON data (1-10MB) going to a mix of localstorage and indexedDB.
- slow_donkey 8y agoHave you looked into using a fetch event hook? The first thing I thought of was an Axios interceptor if you're using Axios or other http lib. That should allow you to sum up download sizes.
- wbercx 8y agoThanks for this! I've recently been asked how much data our React Native app uses. I totally hadn't thought of using Axios' interceptors to track this. So obvious!
- pmlnr 8y agoMay I ask the justification to download 1-10MB JSON on the user's system without the user being aware?
- ahsanejaz 8y agoYou also cache regular web resources like images. It is for the user's benefit since next visit to the site can be faster.
- pmlnr 8y agoYou misunderstand. Service worker traffic is invisible, unlike loading an image and generally speaking can't be governed, unlike visible elements. Loading 1-10MB JSON might drain a significant portion of mobile data. It could take a long time, meaning it may need to re-start it a couple of times, due to, say, a flaky 3G connection. I'm curious on the why - unless this is an announced feature, I don't think this should be an automatic process and should only be done on user demand explicitly.
- sbr464 8y agoI agree with you, there are several settings avail to control what is optimized, it’s typically enabled on faster devices/connections at work. I would be upset as well if a site naively used up a connection in the background.
- sbr464 8y agoThey are aware, it’s business software, syncing records/templates/frequent info etc. It’s only to improve the experience, and it’s controlled by settings/opt-in etc. It’s also configurable to only operate on faster connections/non mobile IP address etc. The main reason I was asking is if you currently benchmark service worker updates with indexedDB for async/larger updates, they still cause a small amount of jank, (at least on larger requests) even though they may use a different process etc. There’s a github repo with a benchmark, this link is older but if you clone the current version and update to the lastest packages, the results are still similar. https://www.google.com/amp/s/nolanlawson.com/2015/09/29/indexeddb-websql-localstorage-what-blocks-the-dom/amp/
- michaelmrose 8y ago"Imagine being able to respond to push notifications, intercept resource requests, and schedule background syncronization, all without the need for a user to actively have your website open in front of them." ".. by authoring special-purpose JavaScript which you register with the browser." Why does this seem like something useful for malware and generally annoying me.
- Brakenshire 8y agoPush requests only exists on Chrome and is behind a permission, intercepting resource requests within the domain of a website could cause some annoyances, can’t see the malware effect immediately. Scheduling a download for a stable connection, again, could be an annoyance, but what’s the malware implication?
- chrismorgan 8y agoThe malware angle is basically service-worker-powered cache poisoning: if you can get the server to serve your code once, users can get a service worker installed, and intercept resource requests under that path. It’s limited in practical value because you have to be able to serve a full JS file as the service worker, rather than just injecting a snippet of JS as the most common technique is, but it is a genuine attack vector.
- johncolanduoni 8y agoService workers automatically reload after 24 hours, regardless of caching headers (though I believe they’ll respect a 304). I believe this was done partially to limit the duration of such a compromise.
- michaelmrose 8y agoI don't want to be compromised at all and it seems like a great way keep it that way is to force web pages to live in you know pages which I can close and know they aren't effecting my browser. It also breaks my mental model of how the browser works in a way that will be incomprehensible to users. Instead of my computer is acting funny I need to reboot we will have my browser is acting funny I need to restart it or we can combine the 2. My browser is acting funny lets power cycle again. Coming soon to a windows PC near you.
- dannyw 8y agoI like service workers, but I don't like the lack of control I have. For example, I want Messenger to send me notifications if I have the tab open, but I don't want the service worker to maintain a persistent connection and send me notifications with the tab closed. Unfortunately, I am not able to block service workers. My only option is to block notifications entirely, which doesn't even stop the service worker.
- ahsanejaz 8y agoThe service worker does not maintain a persistent connection. Some websites/pwa's allow you to configure that.
- bryanrasmussen 8y agobut then you're depending on the website/pwa to be a good citizen and allow you to configure that
- sleepychu 8y agoThat's ok, I'm sure the EU will sort out some kind of service worker popup in due course!
- dannyw 8y agoThe service worker should not be allowed to listen to global-push notifications without me telling it to. The notifications dropdown should be: - Always allow - Allow when open - Disallow
- amelius 8y agoI suppose that depends on the type of browser you use.
- untog 8y agoThe service worker can't maintain a persistent connection. Without an active tab it is shut down after 30 seconds or so. It can receive events via the Push API, which is what you're seeing. But if you refuse notification permissions the site cannot use the Push API. I'm actually not sure how it works when you block notifications after having given permission - it's a requirement that you show a notification in response to a push, so if you're blocked, I'm not sure how the browser registers it. More broadly, I agree that it is strange you can opt into the Push API without a permission prompt. I wish it weren't the case, but I do think it would be confusing to users to request separate push and notification permissions - most consider them to be synonymous, even if they aren't.
- pmlnr 8y agoFirefox: about:config dom.serviceWorkers.enabled;false Why: They bite. The generic idea may even be reasonable (offline working web app), but every single time I encounter service workers they make things worse. If you load a React frontend, it'll, by default, deploy a service worker. Good luck trying to load anything non-react from that resource/server. I never asked for a web app to work in the background once I closed a site. Nobody should be trained to expect websites work in the background - that is not how they are. If there is no tab open, there should be no notification, no nothing. That is how the web works.
- wakeywakeywakey 8y ago> If you load a React frontend, it'll, by default, deploy a service worker. What? > That is how the web works. The web 'experience' has stopped being about fetching static documents in a request/response fashion long ago. Consumers demand rich apps and interactivity, and it appears they're having it their way.
- pmlnr 8y ago> What? https://github.com/facebook/create-react-app/issues/2398 https://github.com/facebook/create-react-app/issues/2398 > Consumers demand rich apps and interactivity They really don't. That's an assumption without data. EDIT: see gov.uk. It works quite well without being fancy.
- wakeywakeywakey 8y ago> https://github.com/facebook/create-react-app/issues/2398 https://github.com/facebook/create-react-app/issues/2398 Equating 'create-react-app' package with React is silly. By that logic, I can wrap $library_of_your_choice in scaffolding and then blame it for the bloat I've chosen to add. > EDIT: see gov.uk. It works quite well without being fancy. We're at an impasse, since you countered my 'assumption without data' with your 'one-off anecdotal evidence'
- htor 8y ago> Consumers demand rich apps and interactivity, and it appears they're having it their way. no consumer ever demanded the web to be like an app. this is marketing baloney crap. stop treating humans browsing the web as targets for advertisement and consumerism.
- baybal2 8y agoI'm very glad about existence of this wonderful extension: https://chrome.google.com/webstore/detail/manage-web-workers/mcojhlgdkpgablplpcfgledhplllmnih https://chrome.google.com/webstore/detail/manage-web-workers...
- mellett68 8y agoWeb workers and service workers do different things
- werdnapk 8y agoNote to Author: Irregardless is not a word.
- bluntfang 8y agoYes, it is. https://www.merriam-webster.com/dictionary/irregardless https://www.merriam-webster.com/dictionary/irregardless
- phkahler 8y agoIt's a crappy word then.
- RegBarclay 8y ago"Use regardless instead."
- camflan 8y agoWebster’s is a descriptive dictionary, which will include nonstandard words so that it can _describe_ them, and provide guidance on what should be used instead. Just like in that link - it suggests the use of “regardless”
- eletious 8y agoMaybe I'm out of touch, but for messaging apps wouldn't it be desirable to have an actual service from a native app that you can enable/disable in your OS?
- Ajedi32 8y agoOn some platforms, progressive web apps effectively _are_ native: https://developers.google.com/web/fundamentals/integration/webapks https://developers.google.com/web/fundamentals/integration/w...
- c0brac0bra 8y ago"Imagine being able to respond to push notifications" Yes, wouldn't it be wonderful if we could do this in all major browsers today? sigh