Intent to Deprecate and Remove: cache.addAll() duplicate requests

722 views
Skip to first unread message

Ben Kelly

unread,
Sep 19, 2018, 4:15:50 PM9/19/18
to blin...@chromium.org

Contact emails

wande...@chromium.org


Spec

https://w3c.github.io/ServiceWorker/#cache-addAll


Summary

The Cache API includes a `cache.addAll()` method that allows a site to fetch and store multiple requests at the same time.  The spec and other browsers will reject the operation if duplicate requests are specified in a single method invocation.


Chrome currently allows these calls to complete with the early request being ignored and the later request “winning”.  Edge matches Chrome’s behavior, but have indicated they would also like to conform to the spec.


To improve browser interoperability we would like to make `cache.addAll()` reject if there are duplicate requests.  We already have the code to do this behind the experimental web features flag in M70. The intent is to add a deprecation message in M71 and then enable the flag by default in M72.


Link to “Intent to Implement” blink-dev discussion

There was no previous intent to implement discussion.  We originally implemented the code as a bug fix. We thought since multiple other browsers shipped this restriction it would be safe.  However, after seeing anecdotal evidence that some sites were using duplicates we decided to move the bug fix under the experimental web features flag while we collected UseCounter data.


Is this feature supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

Yes.


Demo link

https://cache-addall-duplicate-test.glitch.me/


Debuggability

No changes are necessary to devtools.  To aid in debugging the issue, however, the `cache.addAll()` promise will reject with an exception message like:


Cache.addAll(): duplicate requests (https://cache-addall-duplicate-test.glitch.me/?q=foo)


This message is also logged as a console warning starting in M70.  Once the removal ships this warning will be removed and replaced with the promise rejection.


Risks

Interoperability and Compatibility

Currently a number of sites accidentally include a duplicate URL in their `cache.addAll()` calls in their service worker install event handlers.  These service workers fail to install in Firefox and Safari today. Shipping this removal will make these sites fail to install their service worker on Chrome as well.


Edge: Public Support

Firefox: Shipped in Firefox 39

Safari: Shipped (but I’m not sure which version)

Web developers: No signals.


Ergonomics

The `cache.addAll()` method is typically used in the service worker install event handler.  If sites begin triggering rejections in these cases then their service worker will not install.


As far as I know there is not a good use case for using duplicate requests in `cache.addAll()` calls.  All of the sites I have seen that do it appear to have accidentally included a duplicate in their list of assets.  There is a real downside to permitting these duplicates because it results in wasted bandwidth. Since the browser must handle VARY headers it's not possible to filter out duplicates before fetching the Response from the network.


If a site really wants to make duplicate requests it can do so directly with the `fetch()` function.


Is this feature fully tested by web-platform-tests? Link to test suite results from wpt.fyi.

Yes, there were existing WPT tests and we added a couple more cases to better test VARY header interactions.  See:


https://wpt.fyi/results/service-workers/cache-storage/serviceworker/cache-add.https.html?label=experimental


Note, this shows “experimental” support where the feature flag is enabled in chrome and we pass the tests.


Usage information from UseCounter

0.002%


This is based on about two weeks of time on dev channel and one week of time on beta channel.  If the UseCounter value changes after M70 hits stable we can revise our deprecation and removal plan.


The UseCounter probably includes mostly results from service worker install event handlers.  Any use at the time of the service worker installation is counted against all pages controlled by that service worker.


Entry on the feature dashboard

https://www.chromestatus.com/feature/5622587912617984


Yoav Weiss

unread,
Sep 24, 2018, 7:15:58 AM9/24/18
to Ben Kelly, blin...@chromium.org
LGTM1

On Wed, Sep 19, 2018 at 10:15 PM Ben Kelly <wande...@chromium.org> wrote:

Contact emails

wande...@chromium.org


Spec

https://w3c.github.io/ServiceWorker/#cache-addAll


Summary

The Cache API includes a `cache.addAll()` method that allows a site to fetch and store multiple requests at the same time.  The spec and other browsers will reject the operation if duplicate requests are specified in a single method invocation.


Chrome currently allows these calls to complete with the early request being ignored and the later request “winning”.  Edge matches Chrome’s behavior, but have indicated they would also like to conform to the spec.


To improve browser interoperability we would like to make `cache.addAll()` reject if there are duplicate requests.  We already have the code to do this behind the experimental web features flag in M70. The intent is to add a deprecation message in M71 and then enable the flag by default in M72.


Link to “Intent to Implement” blink-dev discussion

There was no previous intent to implement discussion.  We originally implemented the code as a bug fix. We thought since multiple other browsers shipped this restriction it would be safe.  However, after seeing anecdotal evidence that some sites were using duplicates we decided to move the bug fix under the experimental web features flag while we collected UseCounter data.


That does indeed sounds like a bug fix. Thanks for taking the cautious path and gathering data before changing behaviour.
That's below the typical threshold, and the fact that those sites are already broken in Firefox and Safari certainly helps.
Reversing course if eventual usage in stable turns out to be higher than expected SGTM.
 

The UseCounter probably includes mostly results from service worker install event handlers.  Any use at the time of the service worker installation is counted against all pages controlled by that service worker.


Entry on the feature dashboard

https://www.chromestatus.com/feature/5622587912617984


--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAK7rkMh11nKxhHjh_wZ2_kWSzuVgRGWrJ8s5e6Boz92eaQC9PA%40mail.gmail.com.

Daniel Bratell

unread,
Sep 24, 2018, 12:44:40 PM9/24/18
to Ben Kelly, Yoav Weiss, blin...@chromium.org
Looks like an increasing number of uses as service worker use increases so I think it's better to kill it quickly or a much longer process will be needed.

LGTM2.

/Daniel
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CACj%3DBEgB6f7TfxDmHXjcEDNQdnXpZ-Hz%2B4ayV%3DY7oyeP3m8hvg%40mail.gmail.com.



--
/* Opera Software, Linköping, Sweden: CEST (UTC+2) */

Chris Harrelson

unread,
Sep 24, 2018, 1:00:45 PM9/24/18
to Daniel Bratell, wande...@chromium.org, Yoav Weiss, blink-dev

Ben Kelly

unread,
Sep 27, 2018, 10:42:12 AM9/27/18
to Chris Harrelson, bra...@opera.com, Yoav Weiss, blin...@chromium.org
For the search index, here is the deprecation message users will see:

"[Deprecation] Cache.addAll() with duplicate requests is deprecated and will be removed in M72, around January 2019. See https://www.chromestatus.com/features/5622587912617984 for more details."

Ben Kelly

unread,
Oct 16, 2018, 9:13:59 AM10/16/18
to Chris Harrelson, bra...@opera.com, Yoav Weiss, blin...@chromium.org
The removal is now active as of canary 72.0.3582.0.

For reference, the use counter continues to bounce around between 0.0015% and 0.003% usage.
Reply all
Reply to author
Forward
0 new messages