GoogleChrome / GoogleChrome/workbox

new "cachedResponseIsAbsent" method for custom plugins

Open
#3,298 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
13k
Forks
880
Avg merge
2h 44m
Merged PRs (30d)
8

Description

Feature Request Description:

I would like to request for a new method for custom plugins called "cachedResponseIsAbsent" for example.

What is the use case? To be informed if no cached response was found and the request will have to solely depend on a fetch. Indeed, when requestWillFetch is fired within a StaleWhileRevalidate strategy plugin, we still do not know if a cached response will be found. Our service worker is using client.postMessage() to inform the client of these different events so as to fine-tune the UX. The only solution for now seems to set a timeOut after receiving a message from requestWillFetch to see if cachedResponseWillBeUsed will also fire just after. Instead, it would be easier to have a "cachedResponseIsAbsent" message the client.

In our specific case:
If cachedResponseWillBeUsed fires after requestWillFetch fires, we show the cached content + an "updating" message
If cachedResponseIsAbsent fires instead after requestWillFetch fires, there is no cached content to display so we instead show some placeholders without any updating message.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.