[webkit-changes] [WebKit/WebKit] c68a38: Duplicate requests due to speculative parsing with...

youennf noreply at github.com
Thu Dec 14 01:35:04 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c68a38f2d6ebefb7a1d63d53ee6e5456327dd34a
      https://github.com/WebKit/WebKit/commit/c68a38f2d6ebefb7a1d63d53ee6e5456327dd34a
  Author: Youenn Fablet <youennf at gmail.com>
  Date:   2023-12-14 (Thu, 14 Dec 2023)

  Changed paths:
    A LayoutTests/http/wpt/service-workers/resources/serviceworker-and-preloads-iframe.html
    A LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-img.png
    A LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-img.png.headers
    A LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-script.js
    A LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-script.js.headers
    A LayoutTests/http/wpt/service-workers/serviceworker-and-preloads-expected.txt
    A LayoutTests/http/wpt/service-workers/serviceworker-and-preloads-worker.js
    A LayoutTests/http/wpt/service-workers/serviceworker-and-preloads.html
    M Source/WebCore/loader/cache/CachedResourceLoader.cpp
    M Source/WebCore/loader/cache/CachedResourceLoader.h

  Log Message:
  -----------
  Duplicate requests due to speculative parsing with active service worker
https://bugs.webkit.org/show_bug.cgi?id=250454
rdar://104377727

Reviewed by Chris Dumez.

In case a service worker is located in the same process as a controlled document, they both share the same memory cache.
Before the patch, in case of preloads triggered byt he speculative parser and the preloads are not cacheable, the following would happen:
- Trigger a preload, which gets registered in the memory cache.
- Let the service worker handle the preload, which triggers a fetch of the same resource.
- This fetch will remove the preload resource from the memory cache and do the actual network load.
- The real load of the HTML resource kicks in and tries to load the resource from the memory cache.
- Given the resource is not a preload and is not reusable according the HTTP headers, a new load is triggered.

This makes it so that two loads are happening for the same resource (one for the preload and one for the actual load).
To resolve the issue, we do not add the service worker fetch resource in the memory cache in the following case:
- There is an existing cached resource, which is a preload, and not a service worker request.
- The new request is a service worker request.

This ensures that we keep the preload cached resource in the memory cache which allows reuse when the actual load happens.

* LayoutTests/http/wpt/service-workers/resources/serviceworker-and-preloads-iframe.html: Added.
* LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-img.png: Added.
* LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-img.png.headers: Added.
* LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-script.js: Added.
* LayoutTests/http/wpt/service-workers/resources/serviceworker-preload-script.js.headers: Added.
* LayoutTests/http/wpt/service-workers/serviceworker-and-preloads-expected.txt: Added.
* LayoutTests/http/wpt/service-workers/serviceworker-and-preloads-worker.js: Added.
* LayoutTests/http/wpt/service-workers/serviceworker-and-preloads.html: Added.
* Source/WebCore/loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::updateCachedResourceWithCurrentRequest):
(WebCore::computeShouldAddToMemoryCache):
(WebCore::CachedResourceLoader::requestResource):
(WebCore::CachedResourceLoader::loadResource):
* Source/WebCore/loader/cache/CachedResourceLoader.h:

Canonical link: https://commits.webkit.org/272024@main




More information about the webkit-changes mailing list