Category: Data

In this article we are going to look at one of the service worker functions such as cache and offline mode.To start, we will need a resource server. Combining the use of fetch API and cache API, we can create different caching strategies for our service workers.

If it is the first time and it does not find the cached resource, it will return the resource from the network and will store cache for the next time that is consulted.

If there is an error in the network response it will return the resource directly from cache, if any.

If the registration has worked correctly, we will be able to see our registered service worker as in the following image: Our service worker consists of two parts, the first to capture the requests and/or cache them.And the second part, a mechanism to reset in case we need to empty the cache completely if we have any cache first.

Related Articles