Handling navigationPreload #136
-
I get an error in the browser saying my preload was cancelled because I didn't wait for it to settle. Do I understand correctly that I'm supposed to provide a matcher for those myself if I wanna avoid that error? |
Beta Was this translation helpful? Give feedback.
Answered by
DuCanhGH
Apr 28, 2024
Replies: 1 comment 4 replies
-
As far as I understand it would be sufficient for me to just provide a default handler like that, right? serwist.setDefaultHandler(({ event, request }) => {
if (event instanceof FetchEvent) {
return event.preloadResponse.then((preload) => {
if (preload instanceof Response) {
return preload;
}
return fetch(request);
});
}
return fetch(request);
}, "GET"); but perhaps a specific handler would be better to avoid that overhead for all non-navigation requests |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@HugeLetters yes, you may want to register a
NavigationRoute
rather than usesetDefaultHandler
in this case.You're right. If Serwist can't find a handler, the request would be treated as if there weren't a service worker intercepting it.
Edit: The
Serwist
class also provides theprecacheOptions.navigateFallback
option, so you don't have to use the lower levelNavigationRoute
class. Unless you don't use an app shell, or that shell is not precached, that is.