Skip to content

Commit

Permalink
perf(pwa): store updated content only
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket committed Oct 18, 2024
1 parent eefb8c6 commit 191c21a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion static/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ onfetch = (event) => {
return cache.match(event.request)
.then((cachedResponse) => {
const fetchedResponse = fetch(event.request).then((networkResponse) => {
if (networkResponse.status < 400) {
if ((networkResponse.status < 400)
&& (cachedResponse.headers.get("Last-Modified")
!== networkResponse.headers.get("Last-Modified"))) {
console.log("Caching the response to", event.request.url);
cache.put(event.request, networkResponse.clone());
} else {
Expand Down

0 comments on commit 191c21a

Please sign in to comment.