1- // Initialize Firebase
2- var config = {
3- apiKey : "AIzaSyBX6l4geba-CjXE_WlQwOX6pxCIrVl-tjk" ,
4- authDomain : "wise-bongo-209220.firebaseapp.com" ,
5- databaseURL : "https://wise-bongo-209220.firebaseio.com" ,
6- projectId : "wise-bongo-209220" ,
7- storageBucket : "wise-bongo-209220.appspot.com" ,
8- messagingSenderId : "926874022337"
9- } ;
10- firebase . initializeApp ( config ) ;
11- export const inicializarFirebase = ( ) => {
12- firebase . initializeApp ( {
13- messagingSenderId : '926874022337'
14- } ) ;
15- navigator . serviceWorker
16- . register ( '/my-sw.js' )
17- . then ( ( registration ) => {
18- firebase . messaging ( ) . useServiceWorker ( registration ) ;
19- } ) ;
20- }
21-
221var cacheName = 'v1' ;
23- // A list of local resources we always want to be cached.
24- var cacheFiles = [
25- '/' ,
26- //php
27- // 'app/public/index.php',
28- //blade
29- //'app/resources/views/pages/home.blade.php',
30- //css
31- //'app/public/css/index.min.css',
32- //jquery
33- //'app/public/css/jquery/jquery-ui.min.js',
34- //'app/public/css/jquery/jquery-ui.js',
35- //javascript files
36- //'app/public/js/jquery-3.1.1.js',
37- //'app/public/js/utils.js',
38- //'home.js',
39- //'app/public/js/hover_text.js',
40- //'app/public/js/service_worker_script.js',
41- //assets
42- //'app/public/images/logo.svg',
43- ]
44- self . addEventListener ( 'install' , function ( e ) {
45- console . log ( "[ServiceWorker] Installed" ) ;
2+
3+ var cacheFiles = [ ] ;
4+
5+ self . addEventListener ( 'install' , function ( e ) {
466 try {
477 e . waitUntil (
488 caches . open ( cacheName ) . then ( function ( cache ) {
49- console . log ( "[ServiceWorker] Caching cacheFiles" ) ;
509 return cache . addAll ( cacheFiles ) ;
5110 } )
5211 )
5312 } catch ( e ) {
5413 console . log ( e ) ;
5514 }
15+
5616} )
5717
5818self . addEventListener ( 'activate' , function ( e ) {
59- console . log ( "[ServiceWorker] Activated" ) ;
19+ e . waitUntil (
20+ caches . keys ( ) . then ( function ( cacheNames ) {
21+ return Promise . all ( cacheNames . map ( function ( thisCacheName ) {
22+
23+ if ( thisCacheName !== cacheName ) {
24+ return caches . delete ( thisCacheName ) ;
25+ }
26+ } ) ) ;
27+ } )
28+ ) ;
29+ e . waitUntil (
30+
31+ caches . keys ( ) . then ( function ( cacheNames ) {
32+ return Promise . all ( cacheNames . map ( function ( thisCacheName ) {
33+
34+ if ( thisCacheName !== cacheName ) {
35+ return caches . delete ( thisCacheName ) ;
36+ }
37+ } ) ) ;
38+ } )
39+ ) ;
6040} )
6141
6242self . addEventListener ( 'fetch' , function ( e ) {
63- //console.log("[ServiceWorker] Fetching", e.request.url);
43+ e . respondWith (
44+
45+ caches . match ( e . request )
46+
47+
48+ . then ( function ( response ) {
49+
50+ if ( response ) {
51+ return response ;
52+ }
53+
54+ var requestClone = e . request . clone ( ) ;
55+ return fetch ( requestClone )
56+ . then ( function ( response ) {
57+
58+ if ( ! response ) {
59+ return response ;
60+ }
61+
62+ var responseClone = response . clone ( ) ;
63+ caches . open ( cacheName ) . then ( function ( cache ) {
64+ cache . put ( e . request , responseClone ) ;
65+ return response ;
66+ } ) ;
67+
68+ } )
69+ . catch ( function ( err ) {
70+ console . log ( '[ServiceWorker] Error Fetching & Caching New Data' , err ) ;
71+ } ) ;
72+
73+
74+ } )
75+ ) ;
6476} )
0 commit comments