Listening to Fetch Events
Learn how to add listeners to the fetch event of the service worker.
We'll cover the following
Every time the browsers try to fetch any resources (like images, style sheets, scripts, etc.) by sending requests to the network, the fetch
event of the service worker gets triggered. To listen to these fetch
events of service workers, we need to register a fetch
event handler, which triggers the Add-to-Home-screen feature.
Registering the fetch
event handler
We can register the fetch
event handler as the callback to the addEventListener
method provided by the self
object of the service worker.
Get hands-on with 1200+ tech skills courses.