Service Workers

Last updated on June 26, 2024.

This guide covers the definition and functionality of Service Workers and detailed instructions on effectively employing them within the Insites.

Service Workers

A Service Worker is a background script that runs independently of web pages in your browser. It enables the implementation of features that do not require user interaction or the presence of a web page. Essentially, a Service Worker is a JavaScript file that operates on a separate thread from the main browser, intercepts network requests, caches or retrieves resources from the cache, and facilitates the delivery of push notifications.

Service Workers offer a range of capabilities that enhance web applications, including transforming an application into a Progressive Web App (PWA), sending push notifications, and improving performance through caching mechanisms. They introduce new web features that empower developers to create richer and more engaging web experiences.

Usage: Adding a Service Worker JavaScript file on root scope

Service Workers are limited to intercepting requests within their specified scope for security reasons.

For instance, if you have a Service Worker named located at , it can only control requests made to paths starting with . This is why it is often recommended to place your Service Worker file at the root domain, allowing you to have control over all incoming requests to your application.

You can achieve this in Insites by placing your Service Worker files in the directory. To maintain consistency, it is advised to use the following naming pattern for your Service Worker files:

  • (and )
  • (and )

Examples:

  • ,
  • ,

References

Please visit the following references for more information on Service Workers:

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.