...

/

Workbox

Workbox

Workbox is considered the state of the art for building PWAs. It is framework agnostic. That is, we can use it with any JavaScript framework or vanilla solutions.

widget

Setup

Workbox is an open-source project from Google, and it is currently the most widely used tool to develop PWAs.

It consists of a set of libraries and Node modules to abstract the complexity of service workers and caching strategies. This allows us to focus on the application business logic without worrying about the underlying PWA details.

Workbox gives developers more robust and granular control compared to PWA Builder, but, on the other side, it also expects a minimum of JavaScript and service workers know-how from the developer.


Install via CDN

To get started, we first need to create a service worker to import the Workbox file workbox-sw.js.

Press + to interact
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
if (workbox) {
console.log(`Workbox is loaded!!`);
} else {
console.log(`Workbox failed to load`);
}

The importScripts() method belongs to the WorkerGlobalScope ...

Access this course and 1400+ top-rated courses and projects.