You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
After the precache we define the routes and strategies for the network call after the install events. In my implementation I decided to setup a cache for each one of the following assets:
102
+
103
+
* styles (CSS files)
104
+
* scripts (JavaScript files)
105
+
* documents (HTML files)
106
+
* fonts
107
+
* images
108
+
109
+
Each route is registered in the service worker with the `registerRoute` function. It expects 3 parameters: a regex that defines the URLs intercepted by the route, a strategy handler and eventually the HTTP method expected on the route (the last two parameters are optional and could be substituted by a `Route` object that contains this 3 params). In our case, as a consequence of the fact that I decided that all the routes must be served with a `CacheFirst` strategy, we can define a `registerRoute` function that defines a route with a cache first strategy given the regex of the route, the cache name and the `ExpirationPlugin`. What is an `ExpirationPlugin`? It is a class that define the retention policy of the cache to which it is assigned. In our case I defined different `ExpirationPlugin` instances based on the policy I chosen for each media type supported by the routes we defined above:
110
+
111
+
* 15 days for the styles
112
+
* 180 days for the fonts
113
+
* 60 days for the images
114
+
* 60 days for the documents
115
+
116
+
Above you can see the implementation for the routes and strategies.
0 commit comments