File tree Expand file tree Collapse file tree 6 files changed +69
-4
lines changed Expand file tree Collapse file tree 6 files changed +69
-4
lines changed Original file line number Diff line number Diff line change 11/public /build
22/node_modules
3+ /public /sw-toolbox.js
Original file line number Diff line number Diff line change 99 "url" : " http://github.com/insin/react-hn.git"
1010 },
1111 "scripts" : {
12- "build" : " npm run lint && nwb build" ,
13- "lint" : " eslint . " ,
12+ "build" : " npm run lint && cp node_modules/sw-toolbox/sw-toolbox.js public/sw-toolbox.js && nwb build && npm run precache " ,
13+ "lint" : " eslint src " ,
1414 "lint:fix" : " eslint --fix ." ,
15- "start" : " nwb serve"
15+ "start" : " nwb serve" ,
16+ "precache" : " sw-precache --root=public --config=sw-precache-config.json"
1617 },
1718 "dependencies" : {
1819 "events" : " 1.1.0" ,
2829 },
2930 "devDependencies" : {
3031 "eslint-config-jonnybuchanan" : " 2.0.3" ,
31- "nwb" : " 0.8.1"
32+ "nwb" : " 0.8.1" ,
33+ "sw-precache" : " ^3.1.1" ,
34+ "sw-toolbox" : " ^3.1.1"
3235 }
3336}
Original file line number Diff line number Diff line change 3636 < div id ="app "> </ div >
3737 < script src ="build/vendor.js "> </ script >
3838 < script src ="build/app.js "> </ script >
39+ < script >
40+ if ( 'serviceWorker' in navigator ) {
41+ navigator . serviceWorker . register ( './service-worker.js' , {
42+ scope : './'
43+ } )
44+ . then ( function ( registration ) {
45+ registration . onupdatefound = function ( ) {
46+ if ( navigator . serviceWorker . controller ) {
47+ var installingWorker = registration . installing ;
48+
49+ installingWorker . onstatechange = function ( ) {
50+ switch ( installingWorker . state ) {
51+ case 'installed' :
52+ break ;
53+ case 'redundant' :
54+ throw new Error ( 'The installing ' +
55+ 'service worker became redundant.' ) ;
56+ default :
57+ // Ignore
58+ }
59+ } ;
60+ }
61+ } ;
62+ } ) . catch ( function ( e ) {
63+ console . error ( 'Error during service worker registration:' , e ) ;
64+ } ) ;
65+ } else {
66+ console . log ( 'service worker is not supported' ) ;
67+ }
68+ </ script >
3969 </ body >
4070</ html >
Original file line number Diff line number Diff line change 1+ // global.toolbox is defined in a different script, sw-toolbox.js, which is part of the
2+ // https://github.com/GoogleChrome/sw-toolbox project.
3+ // That sw-toolbox.js script must be executed first, so it needs to be listed before this in the
4+ // importScripts() call that the parent service worker makes.
5+ ( function ( global ) {
6+ 'use strict'
7+
8+ // See https://github.com/GoogleChrome/sw-toolbox/blob/6e8242dc328d1f1cfba624269653724b26fa94f1/README.md#toolboxroutergeturlpattern-handler-options
9+ // and https://github.com/GoogleChrome/sw-toolbox/blob/6e8242dc328d1f1cfba624269653724b26fa94f1/README.md#toolboxfastest
10+ // for more details on how this handler is defined and what the toolbox.fastest strategy does.
11+ global . toolbox . router . get ( '/(.*)' , global . toolbox . fastest , {
12+ origin : / \. (?: g o o g l e a p i s | g s t a t i c | f i r e b a s e i o ) \. c o m $ /
13+ } )
14+ global . toolbox . router . get ( '/(.+)' , global . toolbox . fastest , {
15+ origin : 'https://hacker-news.firebaseio.com'
16+ } )
17+ global . toolbox . router . get ( '/(.+)' , global . toolbox . fastest , {
18+ origin : 'https://s-usc1c-nss-136.firebaseio.com'
19+ } )
20+ } ) ( self )
21+
Original file line number Diff line number Diff line change 1+ // This file is intentionally without code.
2+ // It's present so that service worker registration will work when serving from the 'public' directory.
Original file line number Diff line number Diff line change 1+ {
2+ "importScripts" : [
3+ " sw-toolbox.js" ,
4+ " runtime-caching.js"
5+ ],
6+ "stripPrefix" : " public/" ,
7+ "verbose" : true
8+ }
You can’t perform that action at this time.
0 commit comments