Search⌘ K
AI Features

Updating Cached Files

Explore how to update cached files in progressive web applications by using cache versioning within service workers. Understand when and how to update service worker code, manage new cache versions, and delete outdated caches during the activate event to ensure users get the latest files seamlessly.

We need to make changes to the app during development and after deployment. Then how can we update the static files we cache during pre-caching and force the browsers to cache and use the latest files?

The browser won’t update the static cache by updating just our static files and not updating the service worker. This is because we use the service worker to cache the static files. For every page request, if we first look in the cache, the browser will continue to serve the user with the outdated cached content without reaching the server.

Pre-caching is implemented during the install event, which is fired only once for each new service worker. So if we don’t change the service worker code, the browser will not update it, no pre-caching will occur, and the browser will keep the outdated assets in the cache storage.

The standard solution to this problem is to maintain cache versions. ...