@@ -3,55 +3,24 @@ var filesToCache = [
33 '/' ,
44 '/index.html' ,
55 '/css/style.css' ,
6- '/js/main.js'
6+ '/js/main.js' ,
7+ '/images/'
78] ;
89
910/* Start the service worker and cache all of the app's content */
10- self . addEventListener ( 'install' , function ( evt ) {
11- evt . waitUntil (
12- caches . open ( cacheName )
13- . then ( function ( cache ) {
14- return cache . addAll ( filesToCache ) ;
15- } )
11+ self . addEventListener ( 'install' , function ( e ) {
12+ e . waitUntil (
13+ caches . open ( cacheName ) . then ( function ( cache ) {
14+ return cache . addAll ( filesToCache ) ;
15+ } )
1616 ) ;
1717} ) ;
1818
1919/* Serve cached content when offline */
20- self . addEventListener ( 'fetch' , function ( evt ) {
21- if ( evt . request . method !== 'GET' ) {
22- return ;
23- }
24- evt . respondWith ( fromCache ( evt . request ) ) ;
25-
26- evt . waitUntil ( update ( evt . request ) . then ( refresh ) )
27- } ) ;
28-
29- function fromCache ( request ) {
30- return caches . open ( cacheName )
31- . then ( function ( cache ) {
32- return cache . match ( request ) ;
20+ self . addEventListener ( 'fetch' , function ( e ) {
21+ e . respondWith (
22+ caches . match ( e . request ) . then ( function ( response ) {
23+ return response || fetch ( e . request ) ;
3324 } )
34- }
35-
36- function update ( request ) {
37- return caches . open ( cacheName ) . then ( function ( cache ) {
38- return fetch ( request ) . then ( function ( response ) {
39- return cache . put ( request , response . clone ( ) ) . then ( function ( ) {
40- return response ;
41- } ) ;
42- } ) ;
43- } ) ;
44- }
45-
46- function refresh ( response ) {
47- return self . clients . matchAll ( ) . then ( function ( clients ) {
48- clients . forEach ( function ( client ) {
49- var message = {
50- type : 'refresh' ,
51- url : response . url ,
52- eTag : response . headers . get ( 'ETag' )
53- } ;
54- client . postMessage ( JSON . stringify ( message ) ) ;
55- } ) ;
56- } ) ;
57- }
25+ ) ;
26+ } ) ;
0 commit comments