File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414 </ main >
1515</ body >
1616< script >
17+
18+ async function navigate ( url ) {
19+ const page = new URL ( url ) . searchParams . get ( "page" ) || 1 ;
20+ const stream = document . body . streamAppendHTMLUnsafe ( ) ;
21+ const response = await fetch ( "/content?page=" + page ) ;
22+ await response . body
23+ . pipeThrough ( new TextDecoderStream ( ) )
24+ . pipeTo ( stream ) ;
25+ }
1726 const loaded = new Promise ( ( resolve ) => {
1827 window . onload = async ( ) => {
1928 navigator . serviceWorker . register ( "./sw.js" ) ;
2029 await navigator . serviceWorker . ready ;
2130 console . log ( "Service worker ready" ) ;
31+ await navigate ( location . href ) ;
2232 resolve ( ) ;
2333 } ;
2434 } ) ;
2838 event . intercept ( {
2939 async handler ( ) {
3040 await loaded ;
31- const url = new URL ( event . destination . url ) ;
32- const page = url . searchParams . get ( "page" ) ;
33- const stream = document . body . streamAppendHTMLUnsafe ( ) ;
34- const response = await fetch ( "/content?page=" + page ) ;
35- await response . body
36- . pipeThrough ( new TextDecoderStream ( ) )
37- . pipeTo ( stream ) ;
38- } ,
41+ await navigate ( event . destination . url ) ;
42+ }
3943 } ) ;
4044 }
4145 } ) ;
You can’t perform that action at this time.
0 commit comments