Functional Events of the Service Worker

Dive deeper into the functional events of service workers.

The functional events of a service worker are related to the functional requirements of our app. Let’s explore them one by one.

The fetch event

The fetch event is triggered when:

  • A browser sends a fetch request for loading some assets (CSS, JS files).
  • A page-related JavaScript initiates a fetch request using the Fetch API.

But the fetch event is not triggered by the XMLHTTPRequest and the Ajax requests.

A service worker can work as a network proxy. Therefore, we can do the following actions:

  • React to these fetch events in the service worker.
  • Manipulate or block these requests.
  • Return cached assets as a response to these requests.

Get hands-on with 1400+ tech skills courses.