Introduction to the Cache API
Explore how to use the Cache API to control resource caching in progressive web apps. Understand its role in offline availability, serving cached content, and managing cache through service workers to improve app reliability and performance.
We'll cover the following...
Caching is an essential part of web applications. Today, most hosting providers provide some caching services from their servers. On the other hand, browsers also cache the resources returned from the network requests made by the web apps based on their priorities.
Why do we need a new API if we already have servers and browsers that provide caching? The following reasons explain why:
- The caching done by servers is mainly for faster page loads and to prevent the heavy usage of the server’s resources. The server caching can’t be used while offline because even to reach out to the server, we need to be online.
- The caching done by browsers isn’t predictable because we don’t know which resources will be cached. Another drawback of the browser’s cache is that it only helps until the user refreshes the page.
To make web apps behave like native apps, we need more control over the caching process to add, update, and delete resources when needed. This is where the Cache API is useful.