Search⌘ K
AI Features

Workbox

Explore how Workbox streamlines the development of Progressive Web Apps by simplifying service worker setup, routing, and caching strategies. Understand the core concepts of routes, caching modules, and debugging to build robust offline-capable web applications with granular control and ease.

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.

JavaScript (JSX)
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 ...