Skip to content

Commit

Permalink
Try to force load index from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed Oct 7, 2024
1 parent 21aa89d commit 42a95b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion PWA/public/Services/FetchEventHandlers/HomepageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ export class HomepageHandler {
return event.request.url.includes(RouteEvents.home);
}
async handleEvent(event) {
return fetch(RouteEvents.home);
const responseFromCache = await caches.match(event.request);
if (responseFromCache) {
console.log("Retrieved index from cache 🎉");
return responseFromCache;
}
else {
console.log("Failed to retrief index from cache :(");
return fetch(RouteEvents.home);
}
}
}
2 changes: 1 addition & 1 deletion PWA/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<!-- <a class="navbar-item">-->
<img src="images/ReliefBox-horizontal-nobackground.png" width="220" height="30">
<!-- </a>-->
<div class="navbar-item">Alpha 0.1.5</div>
<div class="navbar-item">Alpha 0.1.8</div>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
Expand Down
9 changes: 8 additions & 1 deletion PWA/src/Services/FetchEventHandlers/HomepageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export class HomepageHandler implements FetchEventHandler {
}

async handleEvent(event: FetchEvent): Promise<Response> {
return fetch(RouteEvents.home)
const responseFromCache = await caches.match(event.request)
if(responseFromCache) {
console.log("Retrieved index from cache 🎉")
return responseFromCache
} else {
console.log("Failed to retrief index from cache :(")
return fetch(RouteEvents.home)
}
}
}

0 comments on commit 42a95b4

Please sign in to comment.