3 ms·
This is an incredible API I wish existed in the browser (maybe over WebRTC?) addEventListener("fetch", (event) => { event.respondWith(new Response("H
by brrrrrm 4y ago
This is an incredible API I wish existed in the browser (maybe over WebRTC?)
addEventListener("fetch", (event) => {
event.respondWith(new Response("Hello world"));
});
- no_wizard 4y agoThis is how it works with ServiceWorkers[0] [0]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent
- dgb23 4y agoTo expand, this API is directly inspired by the service worker API. A service worker can be thought of as kind of a reverse proxy (logically speaking) that is right in the browser. People are doing very cool things with it. It's a great API for PWAs, SPAs and the like but it also has quite a bit of utility for traditional sites. However there is one big caveat - it's super easy to mess things up with it and it is harder to test and debug (Chrome is the best tool for this IMO as a fan of FF). You better have a very straight forward way to update your service worker right off the bat.