5 ms·
Tell HN: Service Workers === Browser Background Tasks
The term "service worker" has confused me for a while, now I see it to be bad jargon selection. You can use "service workers" to send push notifications, load things from cache, and allow for offline behavior of your application (turn off your wifi and load twitter, for example). I think the term "browser background task" is more apt, I am sad another much more confusing and less relevant term was chosen years ago.
- theGeatZhopa 3y agoThe same applies for the term "demon" in Linux, "services" in Windows. I'm pretty ok with the term "service worker" as I learned, it's a background service doing background things :)
- notRobot 3y agoTechnically it's 'deamon', not 'demon' :) Interesting read: https://man7.org/linux/man-pages/man7/daemon.7.html https://man7.org/linux/man-pages/man7/daemon.7.html
- KomoD 3y agoYou mean daemon, not deamon or demon
- notRobot 3y agoWhoops lmao
- theGeatZhopa 3y agoMatt Damon:)
- kalupa 3y agodaemon? :)
- bheadmaster 3y agoNot an experienced JS dev here - if that is the case, then what is the difference between a "service worker" and a simple async function running in the background?
- dumpsterdiver 3y agoTo my understanding service workers are run in a separate thread using the Web Worker API, and thus are non-blocking unlike standard async functions.
- houseatrielah 3y agoService worker is a whole pattern to give PWA's offline access, ie. intercepting network requests and caching. Async runs on the main thread. If you want to offload work to another thread you use a webworker.
- kevincox 3y agoThere are a lot of differences: 1. Service worker lifetime is not tied to a particular window. They can live across multiple windows either at the same time or across time. (Think of a tab closed then later reopened.) A background function will stop running when the tab is closed. 2. Service workers have some ability to intercept network requests. In a page you could patch APIs like fetch and XMLHttpRequest but you have no ability to intercept image loads or top-level navigations. 3. Other APIs such as receiving push notifications are also tied to service workers (likely because of the lifetime restrictions, otherwise the browser would need to decide which tab to deliver a notification to or open a new one if none are open).
- fortunateregard 3y agoIf you want to intercept and modify a incoming json response for some specific url pattern, would a service worker be a good way to do so? To illustrate, assume I frequently browse a blog and want to trick my browser into thinking that I have "favorited" every post. It's trivial to write a for loop that iterates over response.json and sets `is_favorite = true`. But it's not as clear to me where this script should ideally live in order to have the logic always executed before the response is made available to the site. Your comment made me think about whether I can replace my overkill solution (https://requestly.io/ https://requestly.io/) with something lightweight.
- smartplaya2001 3y agopromiscuous terminology :)
- joshxyz 3y agowe need to decriminalize, legalize, and regulate this industry.
- KRAKRISMOTT 3y agoService workers can function as proxies and man in the middle all requests, they are very different from traditional background tasks in the general sense of the word.