Skip to content

Commit

Permalink
fix(pwa): file SWR filter & allow navigation 403s [LIBS-356] [LIBS-35…
Browse files Browse the repository at this point in the history
…7] (#762)

* fix(pwa): file SWR filter & allow navigation 403s

* fix: use SWR for fonts
  • Loading branch information
KaiVandivier committed Oct 24, 2022
1 parent 891a863 commit bbfd3eb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pwa/src/service-worker/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ export function setUpServiceWorker() {
const navigationRouteHandler = ({ request }) => {
return fetch(request)
.then((response) => {
if (response.type === 'opaqueredirect') {
// It's sending a redirect to the login page. Return
// that to the client
if (response.type === 'opaqueredirect' || !response.ok) {
// It's sending a redirect to the login page,
// or an 'unauthorized'/'forbidden' response.
// Return that to the client
return response
}

// Otherwise return precached index.html
return matchPrecache(indexUrl)
})
.catch(() => {
// Request failed (maybe offline). Return cached response
// Request failed (probably offline). Return cached response
return matchPrecache(indexUrl)
})
}
Expand Down Expand Up @@ -137,13 +138,13 @@ export function setUpServiceWorker() {

// If not recording, fall through to default caching strategies for app
// shell:
// SWR strategy for static assets that can't be precached.
// SWR strategy for image assets that can't be precached.
// (Skip in development environments)
registerRoute(
({ url }) =>
PRODUCTION_ENV &&
urlMeetsAppShellCachingCriteria(url) &&
fileExtensionRegexp.test(url.pathname),
/\.(jpg|gif|png|bmp|tiff|ico|woff)$/.test(url.pathname),
new StaleWhileRevalidate({ cacheName: 'other-assets' })
)

Expand Down

0 comments on commit bbfd3eb

Please sign in to comment.