@@ -47,9 +47,13 @@ setCacheNameDetails({
4747const getStrategy = (
4848 options ?: NetworkFirstOptions | StrategyOptions ,
4949) : NetworkFirst | CacheFirst => {
50- return SW_DEV_URL . some ( ( devDomain ) =>
50+ const isDev = SW_DEV_URL . some ( ( devDomain ) =>
5151 self . location . origin . includes ( devDomain ) ,
52- ) || isApiUrl ( self . location . href )
52+ ) ;
53+ const isApi = isApiUrl ( self . location . href ) ;
54+ const isHTMLRequest = options ?. cacheName ?. includes ( 'html' ) ;
55+
56+ return isDev || isApi || isHTMLRequest
5357 ? new NetworkFirst ( options )
5458 : new CacheFirst ( options ) ;
5559} ;
@@ -77,7 +81,7 @@ self.addEventListener('activate', function (event) {
7781 } ) ,
7882 ) ;
7983 } )
80- . then ( void self . clients . claim ( ) ) ,
84+ . then ( ( ) => self . clients . claim ( ) ) ,
8185 ) ;
8286} ) ;
8387
@@ -139,6 +143,18 @@ setCatchHandler(async ({ request, url, event }) => {
139143 }
140144} ) ;
141145
146+ // HTML documents
147+ registerRoute (
148+ ( { request } ) => request . destination === 'document' ,
149+ new NetworkFirst ( {
150+ cacheName : getCacheNameVersion ( 'html' ) ,
151+ plugins : [
152+ new CacheableResponsePlugin ( { statuses : [ 0 , 200 ] } ) ,
153+ new ExpirationPlugin ( { maxAgeSeconds : 24 * 60 * 60 * DAYS_EXP } ) ,
154+ ] ,
155+ } ) ,
156+ ) ;
157+
142158/**
143159 * External urls cache strategy
144160 */
0 commit comments