fix index.html not being restored from cache when offline on #hash url
This commit is contained in:
parent
df8eed14aa
commit
62c8d6574c
1 changed files with 5 additions and 4 deletions
|
@ -84,16 +84,17 @@ function isCacheableThumbnail(url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseURL = new URL(self.registration.scope);
|
||||||
async function handleRequest(request) {
|
async function handleRequest(request) {
|
||||||
const baseURL = self.registration.scope;
|
const url = new URL(request.url);
|
||||||
if (request.url === baseURL) {
|
if (url.origin === baseURL.origin && url.pathname === baseURL.pathname) {
|
||||||
request = new Request(new URL("index.html", baseURL));
|
request = new Request(new URL("index.html", baseURL.href));
|
||||||
}
|
}
|
||||||
let response = await readCache(request);
|
let response = await readCache(request);
|
||||||
if (!response) {
|
if (!response) {
|
||||||
// use cors so the resource in the cache isn't opaque and uses up to 7mb
|
// use cors so the resource in the cache isn't opaque and uses up to 7mb
|
||||||
// https://developers.google.com/web/tools/chrome-devtools/progressive-web-apps?utm_source=devtools#opaque-responses
|
// https://developers.google.com/web/tools/chrome-devtools/progressive-web-apps?utm_source=devtools#opaque-responses
|
||||||
if (isCacheableThumbnail(new URL(request.url))) {
|
if (isCacheableThumbnail(url)) {
|
||||||
response = await fetch(request, {mode: "cors", credentials: "omit"});
|
response = await fetch(request, {mode: "cors", credentials: "omit"});
|
||||||
} else {
|
} else {
|
||||||
response = await fetch(request);
|
response = await fetch(request);
|
||||||
|
|
Reference in a new issue