File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
assets/mods/pwa/service-worker Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ const fallbacksCache = cachePrefix + 'fallbacks'
1919// Filter the invalid URLs, such as temporary URLs generated by Hugo PostProgress.
2020const precaches = params . precaches . filter ( ( url ) => url . indexOf ( '__h_pp_l1' ) !== 0 )
2121debug ( 'precaches' , precaches )
22+ debug ( 'bypass' , params . bypass )
2223
2324// Register page route with NetworkFirst strategy.
2425// There will be a problem with CacheFirst or StaleWhileRevalidate strategy
@@ -39,6 +40,33 @@ registerRoute(
3940
4041// Register assets routes.
4142const assets = [ 'font' , 'image' , 'script' , 'style' ]
43+
44+ const isBypass = ( url ) => {
45+ if ( params . bypass && params . bypass . includes ( url . href ) ) {
46+ return true
47+ }
48+
49+ return false
50+ }
51+
52+ if ( params . bypass ) {
53+ registerRoute (
54+ ( { request, sameOrigin, url } ) => {
55+ if ( ! isBypass ( url ) ) {
56+ return false
57+ }
58+
59+ // validate origins
60+ if ( sameOrigin ) {
61+ return true
62+ }
63+
64+ return false
65+ } ,
66+ new NetworkOnly ( ) ,
67+ ) ;
68+ }
69+
4270for ( let i in assets ) {
4371 const kind = assets [ i ]
4472 const cache = params . caches [ kind ]
Original file line number Diff line number Diff line change 22{{- $baseURL := partialCached "pwa/functions/baseurl" . }}
33{{/* JS compile options. */}}
44{{- $precaches := slice }}
5+ {{- $bypass := slice }}
56{{- $langs := slice }}
67{{- $host := .Site.BaseURL }}
78{{/* Get precaches pages. */}}
2526{{- with .Store.Get "pwa-precache" }}
2627 {{- $precaches = $precaches | append (uniq .) }}
2728{{- end }}
29+ {{- with .Store.Get "pwa-bypass" }}
30+ {{- $bypass = $bypass | append (uniq .) }}
31+ {{- end }}
2832{{- $pwaParams := .Site.Params.pwa }}
2933{{/* Get precaches from configuration. */}}
3034{{- range $pwaParams.precaches }}
4852 "baseURL" $baseURL
4953 "langs" $langs
5054 "precaches" $precaches
55+ "bypass" $bypass
5156 "debug" $pwaParams.debug
5257 "caches" $pwaParams.caches
5358 "offline_image" $offlineImg
Original file line number Diff line number Diff line change 1+ {{- if and .Page .URL }}
2+ {{- .Page.Store.Add "pwa-bypass" (slice .URL) }}
3+ {{- end }}
You can’t perform that action at this time.
0 commit comments