File tree 5 files changed +60
-0
lines changed
5 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 3
3
< head >
4
4
< meta charset ="UTF-8 " />
5
5
< link rel ="icon " type ="image/svg+xml " href ="/bill-fill.svg " />
6
+ < link rel ="manifest " href ="jamnz.webmanifest " />
6
7
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7
8
< title > Jamnz</ title >
8
9
</ head >
9
10
< body >
10
11
< div id ="root "> </ div >
11
12
< script type ="module " src ="/src/main.tsx "> </ script >
13
+ < script src ="register-sw.js "> </ script >
12
14
</ body >
13
15
</ html >
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " Jamnz" ,
3
+ "icons" : [
4
+ {
5
+ "src" : " JamnzLogo.png" ,
6
+ "sizes" : " 256x256" ,
7
+ "type" : " image/png"
8
+ }
9
+ ],
10
+ "start_url" : " /" ,
11
+ "display" : " standalone"
12
+ }
Original file line number Diff line number Diff line change
1
+ if ( "serviceWorker" in navigator ) {
2
+ window . addEventListener ( "load" , ( ) => {
3
+ navigator . serviceWorker . register ( "/service-worker.js" ) ;
4
+ } ) ;
5
+ }
Original file line number Diff line number Diff line change
1
+ const cacheName = "jamnz" ;
2
+ const staticAssets = [ "./index.html" , "./register-sw.js" ] ;
3
+
4
+ self . addEventListener ( "install" , async ( e ) => {
5
+ const cache = await caches . open ( cacheName ) ;
6
+ await cache . addAll ( staticAssets ) ;
7
+ return self . skipWaiting ( ) ;
8
+ } ) ;
9
+
10
+ self . addEventListener ( "activate" , ( e ) => {
11
+ self . clients . claim ( ) ;
12
+ } ) ;
13
+
14
+ self . addEventListener ( "fetch" , async ( e ) => {
15
+ const req = e . request ;
16
+ const url = new URL ( req . url ) ;
17
+
18
+ if ( url . origin === location . origin ) {
19
+ e . respondWith ( cacheFirst ( req ) ) ;
20
+ } else {
21
+ e . respondWith ( networkAndCache ( req ) ) ;
22
+ }
23
+ } ) ;
24
+
25
+ async function cacheFirst ( req ) {
26
+ const cache = await caches . open ( cacheName ) ;
27
+ const cached = await cache . match ( req ) ;
28
+ return cached || fetch ( req ) ;
29
+ }
30
+
31
+ async function networkAndCache ( req ) {
32
+ const cache = await caches . open ( cacheName ) ;
33
+ try {
34
+ const fresh = await fetch ( req ) ;
35
+ await cache . put ( req , fresh . clone ( ) ) ;
36
+ return fresh ;
37
+ } catch ( e ) {
38
+ const cached = await cache . match ( req ) ;
39
+ return cached ;
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments