A way to specify a pattern of destination URLs to hit/skip SW

Open
#1,454 25 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Domain
web-dev

Research direction

Start by reading the proposal and the related discussions in issues #1026 and #1373. Compare the allowlist header with the alternative and the Declarative Routing proposal, then determine whether the scope is narrowed to the first use case. Done means the behavior and relationship to existing proposals have community agreement.

Written by the indexing model from the issue text.

Description

We often hear a demand for specifying certain set of destination URLs to be intercepted by SW (e.g. #1026, #1373), and this is yet another (lightweight) proposal to address a subset of these using HTTP response headers (therefore it's ephemeral & scoped only to the current navigation).

Proposal: Service-Worker-Fetch-Scope header

  • Allows website to return Service-Worker-Fetch-Scope: <url-scope> HTTP response header to main resource requests, so that they can express what URLs should be hit by their SW for the service worker client that is instantiated by the main resource. <url-scope> can be either “none” or a scope URL.
  • When this is specified, the service-workers mode of all subresource fetch requests from the service worker client that do NOT prefix-match the given scope
    is set to ”none”, i.e. this makes only the subresource requests that match the scope hit the Service Worker.

Examples:

  • Example 1: A site returns Service-Worker-Fetch-Scope: ‘/sw_cache/’ to document requests so that only the subresources whose URL start with /sw_cache/ are intercepted by the SW.
  • Example 2: A site starts to return Service-Worker-Fetch-Scope: “none” after a certain period so that it can skip SW after that. (This could be slightly more efficient than scripting this in SWs as UA can skip routing requests entirely if UA can see it in NavPreload response before/during starting a SW) [EDIT: This use case is a bit hand-wavy, maybe we should focus on the first use-case only]

Alternative can be a header that works opposite, e.g. Service-Worker-Ignore-Fetch or something, while I've heard some sentimenet that allowlisting urls could be handier.

Technically this can be a subset of Declarative Routing proposal (#1373) and can potentially be subsumed by the proposal if we decide to implement it. Motivation of this proposal is to see if we can have a smaller, incremental iteration that can be easier to experiment with.

Dominant language
Bikeshed
Stars
3.6k
Forks
324
Avg merge
14d 22h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from w3c/ServiceWorker

All issues in w3c/ServiceWorker

Similar issues

More Web Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.