Basic Strategies

Caching strategies are the most powerful features of PWAs, and they can deliver huge improvements to our web applications.


Benefits of caching strategies

There are different caching strategies we can adopt to improve the performance of our project.

If a data request is cached, we can deliver it without needing to access the network. This brings the following advantages: on one side, the response is much faster. Conversely, we can provide the data even when the client is offline because we already have it available locally. We cover further advantages in this lesson.

It is essential to note that we must instruct the service worker about which requests it should consider. By default, the SW does not know about this, and even if its role is to intercept HTTP requests, it won’t do anything until we implement some caching strategies.



Cache only

cache-only


This strategy is typically used to implement an offline-first approach in our application. The SW expects to find the requested assets already here.

This strategy can be used for caching static resources, forming our “app shell.” These assets are usually fetched during the SW installation, so they are available locally once the service worker is ready.

Get hands-on with 1200+ tech skills courses.