Skip to content

Commit 29ae596

Browse files
committed
Add more Soft Update on functional events
This changes Handle Fetch and Handle Functional Event to invoke Soft Update even if the service worker doesn't have any event listener registered for the event. (Note that the cases where the request falls back to network still do not trigger Soft Update.) Fixes #905.
1 parent 6c68bd8 commit 29ae596

File tree

4 files changed

+80
-40
lines changed

4 files changed

+80
-40
lines changed

docs/index.bs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,7 +3414,12 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
34143414
</ol>
34153415
</li>
34163416
<li>Let <var>activeWorker</var> be <var>registration</var>'s <a href="#dfn-active-worker">active worker</a>.</li>
3417-
<li>If <var>activeWorker</var>'s <a href="#dfn-set-of-event-types-to-handle">set of event types to handle</a> does not contain <code>fetch</code>, return null.
3417+
<li>If <var>activeWorker</var>'s <a href="#dfn-set-of-event-types-to-handle">set of event types to handle</a> does not contain <code>fetch</code>, then:
3418+
<ol>
3419+
<li>Return null and continue running these steps <a>in parallel</a>.</li>
3420+
<li>If <var>request</var> is a <a>non-subresource request</a>, or <var>request</var> is a <a>subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>'s <a href="#dfn-last-update-check-time">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.</li>
3421+
<li>Abort these steps.</li>
3422+
</ol>
34183423
<p class="note">To avoid unnecessary delays, the Handle Fetch enforces early return when no event listeners have been deterministically added in the service worker's global during the very first script execution.</p>
34193424
</li>
34203425
<li>If <var>activeWorker</var>'s <a href="#dfn-state">state</a> is <em>activating</em>, wait for <var>activeWorker</var>'s <a href="#dfn-state">state</a> to become <em>activated</em>.</li>
@@ -3444,21 +3449,21 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
34443449
<li>Wait for <var>task</var> to have executed or been discarded.</li>
34453450
<li>If <var>respondWithEntered</var> is false, then:
34463451
<ol>
3447-
<li>If <var>eventCanceled</var> is true, return a <a>network error</a> and continue running these substeps <a>in parallel</a>.</li>
3448-
<li>Else, return null and continue running these substeps <a>in parallel</a>.</li>
3452+
<li>If <var>eventCanceled</var> is true, return a <a>network error</a> and continue running these steps <a>in parallel</a>.</li>
3453+
<li>Else, return null and continue running these steps <a>in parallel</a>.</li>
34493454
<li>If <var>request</var> is a <a>non-subresource request</a>, or <var>request</var> is a <a>subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>'s <a href="#dfn-last-update-check-time">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.</li>
34503455
<li>Abort these steps.</li>
34513456
</ol>
34523457
</li>
34533458
<li>If <var>handleFetchFailed</var> is true, then:
34543459
<ol>
3455-
<li>Return a <a>network error</a> and continue running these substeps <a>in parallel</a>.</li>
3460+
<li>Return a <a>network error</a> and continue running these steps <a>in parallel</a>.</li>
34563461
<li>If <var>request</var> is a <a>non-subresource request</a>, or <var>request</var> is a <a>subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>'s <a href="#dfn-last-update-check-time">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.</li>
34573462
</ol>
34583463
</li>
34593464
<li>Else:
34603465
<ol>
3461-
<li>Return <var>response</var> and continue running these substeps <a>in parallel</a>.</li>
3466+
<li>Return <var>response</var> and continue running these steps <a>in parallel</a>.</li>
34623467
<li>If <var>request</var> is a <a>non-subresource request</a>, or <var>request</var> is a <a>subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>'s <a href="#dfn-last-update-check-time">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.</li>
34633468
</ol>
34643469
</li>
@@ -3578,7 +3583,12 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
35783583
<li><a>Assert</a>: a <a>Record</a> with the \[[value]] equals to <var>registration</var> is contained in <a href="#dfn-scope-to-registration-map">scope to registration map</a>.</li>
35793584
<li><a>Assert</a>: <var>registration</var>'s <a href="#dfn-active-worker">active worker</a> is not null.</li>
35803585
<li>Let <var>activeWorker</var> be <var>registration</var>'s <a href="#dfn-active-worker">active worker</a>.</li>
3581-
<li>If <var>activeWorker</var>'s <a href="#dfn-set-of-event-types-to-handle">set of event types to handle</a> does not contain the event type for this functional event, return.
3586+
<li>If <var>activeWorker</var>'s <a href="#dfn-set-of-event-types-to-handle">set of event types to handle</a> does not contain the event type for this functional event, then:
3587+
<ol>
3588+
<li>Return and continue running these steps <a>in parallel</a>.</li>
3589+
<li>If the time difference in seconds calculated by the current time minus <var>registration</var>'s <a href="#dfn-last-update-check-time">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.</li>
3590+
<li>Abort these steps.</li>
3591+
</ol>
35823592
<p class="note">To avoid unnecessary delays, the Handle Functional Event enforces early return when no event listeners have been deterministically added in the service worker's global during the very first script execution.</p>
35833593
</li>
35843594
<li>If <var>activeWorker</var>'s <a href="#dfn-state">state</a> is <em>activating</em>, wait for <var>activeWorker</var>'s <a href="#dfn-state">state</a> to become <em>activated</em>.</li>

docs/index.html

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@
11771177
}
11781178
}
11791179
</style>
1180-
<meta content="Bikeshed 1.0.0" name="generator">
1180+
<meta content="Bikeshed version 645534c1532bca4fdb4f3859efc66268a218d7c8" name="generator">
11811181
<style>/* style-md-lists */
11821182

11831183
/* This is a weird hack for me not yet following the commonmark spec
@@ -1424,7 +1424,7 @@
14241424
<div class="head">
14251425
<p data-fill-with="logo"><a class="logo" href="http://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
14261426
<h1 class="p-name no-ref" id="title">Service Workers Nightly</h1>
1427-
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2016-11-11">11 November 2016</time></span></h2>
1427+
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2016-11-17">17 November 2016</time></span></h2>
14281428
<div data-fill-with="spec-metadata">
14291429
<dl>
14301430
<dt>This version:
@@ -4525,7 +4525,12 @@ <h3 class="heading settled dfn-paneled" data-dfn-type="dfn" data-export="" id="o
45254525
</ol>
45264526
<li>Let <var>activeWorker</var> be <var>registration</var>’s <a href="#dfn-active-worker" id="ref-for-dfn-active-worker-29">active worker</a>.
45274527
<li>
4528-
If <var>activeWorker</var>’s <a href="#dfn-set-of-event-types-to-handle" id="ref-for-dfn-set-of-event-types-to-handle-2">set of event types to handle</a> does not contain <code>fetch</code>, return null.
4528+
If <var>activeWorker</var>’s <a href="#dfn-set-of-event-types-to-handle" id="ref-for-dfn-set-of-event-types-to-handle-2">set of event types to handle</a> does not contain <code>fetch</code>, then:
4529+
<ol>
4530+
<li>Return null and continue running these steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4531+
<li>If <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#non-subresource-request">non-subresource request</a>, or <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#subresource-request">subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-4">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
4532+
<li>Abort these steps.
4533+
</ol>
45294534
<p class="note" role="note">To avoid unnecessary delays, the Handle Fetch enforces early return when no event listeners have been deterministically added in the service worker’s global during the very first script execution.</p>
45304535
<li>If <var>activeWorker</var>’s <a href="#dfn-state" id="ref-for-dfn-state-10">state</a> is <em>activating</em>, wait for <var>activeWorker</var>’s <a href="#dfn-state" id="ref-for-dfn-state-11">state</a> to become <em>activated</em>.
45314536
<li>Invoke <a href="#run-service-worker-algorithm">Run Service Worker</a> algorithm with <var>activeWorker</var> as the argument.
@@ -4555,22 +4560,22 @@ <h3 class="heading settled dfn-paneled" data-dfn-type="dfn" data-export="" id="o
45554560
<li>
45564561
If <var>respondWithEntered</var> is false, then:
45574562
<ol>
4558-
<li>If <var>eventCanceled</var> is true, return a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-network-error">network error</a> and continue running these substeps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4559-
<li>Else, return null and continue running these substeps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4560-
<li>If <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#non-subresource-request">non-subresource request</a>, or <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#subresource-request">subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-4">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
4563+
<li>If <var>eventCanceled</var> is true, return a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-network-error">network error</a> and continue running these steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4564+
<li>Else, return null and continue running these steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4565+
<li>If <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#non-subresource-request">non-subresource request</a>, or <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#subresource-request">subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-5">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
45614566
<li>Abort these steps.
45624567
</ol>
45634568
<li>
45644569
If <var>handleFetchFailed</var> is true, then:
45654570
<ol>
4566-
<li>Return a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-network-error">network error</a> and continue running these substeps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4567-
<li>If <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#non-subresource-request">non-subresource request</a>, or <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#subresource-request">subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-5">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
4571+
<li>Return a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-network-error">network error</a> and continue running these steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4572+
<li>If <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#non-subresource-request">non-subresource request</a>, or <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#subresource-request">subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-6">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
45684573
</ol>
45694574
<li>
45704575
Else:
45714576
<ol>
4572-
<li>Return <var>response</var> and continue running these substeps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4573-
<li>If <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#non-subresource-request">non-subresource request</a>, or <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#subresource-request">subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-6">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
4577+
<li>Return <var>response</var> and continue running these steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4578+
<li>If <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#non-subresource-request">non-subresource request</a>, or <var>request</var> is a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#subresource-request">subresource request</a> and the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-7">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
45744579
</ol>
45754580
</ol>
45764581
</section>
@@ -4684,15 +4689,20 @@ <h3 class="heading settled" id="handle-functional-event-algorithm"><span class="
46844689
<li><a data-link-type="dfn" href="http://tc39.github.io/ecma262/#sec-algorithm-conventions">Assert</a>: <var>registration</var>’s <a href="#dfn-active-worker" id="ref-for-dfn-active-worker-30">active worker</a> is not null.
46854690
<li>Let <var>activeWorker</var> be <var>registration</var>’s <a href="#dfn-active-worker" id="ref-for-dfn-active-worker-31">active worker</a>.
46864691
<li>
4687-
If <var>activeWorker</var>’s <a href="#dfn-set-of-event-types-to-handle" id="ref-for-dfn-set-of-event-types-to-handle-3">set of event types to handle</a> does not contain the event type for this functional event, return.
4692+
If <var>activeWorker</var>’s <a href="#dfn-set-of-event-types-to-handle" id="ref-for-dfn-set-of-event-types-to-handle-3">set of event types to handle</a> does not contain the event type for this functional event, then:
4693+
<ol>
4694+
<li>Return and continue running these steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>.
4695+
<li>If the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-8">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
4696+
<li>Abort these steps.
4697+
</ol>
46884698
<p class="note" role="note">To avoid unnecessary delays, the Handle Functional Event enforces early return when no event listeners have been deterministically added in the service worker’s global during the very first script execution.</p>
46894699
<li>If <var>activeWorker</var>’s <a href="#dfn-state" id="ref-for-dfn-state-14">state</a> is <em>activating</em>, wait for <var>activeWorker</var>’s <a href="#dfn-state" id="ref-for-dfn-state-15">state</a> to become <em>activated</em>.
46904700
<li>Invoke <a href="#run-service-worker-algorithm">Run Service Worker</a> algorithm with <var>activeWorker</var> as the argument.
46914701
<li>
46924702
<a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task">Queue a task</a> <var>task</var> to invoke <var>callbackSteps</var> with <var>activeWorker</var>’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object">environment settings object</a>’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-global">global object</a> as its argument.
46934703
<p>The <var>task</var> <em class="rfc2119" title="MUST">must</em> use <var>activeWorker</var>’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#event-loop">event loop</a> and the <a href="#dfn-handle-functional-event-task-source" id="ref-for-dfn-handle-functional-event-task-source-4">handle functional event task source</a>.</p>
46944704
<li>Wait for <var>task</var> to have executed or been discarded.
4695-
<li>If the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-7">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
4705+
<li>If the time difference in seconds calculated by the current time minus <var>registration</var>’s <a href="#dfn-last-update-check-time" id="ref-for-dfn-last-update-check-time-9">last update check time</a> is greater than 86400, invoke <a href="#soft-update-algorithm">Soft Update</a> algorithm with <var>registration</var>.
46964706
</ol>
46974707
</section>
46984708
<section class="algorithm" data-algorithm="on-client-unload-algorithm">
@@ -6615,8 +6625,8 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
66156625
<b><a href="#dfn-last-update-check-time">#dfn-last-update-check-time</a></b><b>Referenced in:</b>
66166626
<ul>
66176627
<li><a href="#ref-for-dfn-last-update-check-time-1">Update</a> <a href="#ref-for-dfn-last-update-check-time-2">(2)</a> <a href="#ref-for-dfn-last-update-check-time-3">(3)</a>
6618-
<li><a href="#ref-for-dfn-last-update-check-time-4">Handle Fetch</a> <a href="#ref-for-dfn-last-update-check-time-5">(2)</a> <a href="#ref-for-dfn-last-update-check-time-6">(3)</a>
6619-
<li><a href="#ref-for-dfn-last-update-check-time-7">Handle Functional Event</a>
6628+
<li><a href="#ref-for-dfn-last-update-check-time-4">Handle Fetch</a> <a href="#ref-for-dfn-last-update-check-time-5">(2)</a> <a href="#ref-for-dfn-last-update-check-time-6">(3)</a> <a href="#ref-for-dfn-last-update-check-time-7">(4)</a>
6629+
<li><a href="#ref-for-dfn-last-update-check-time-8">Handle Functional Event</a> <a href="#ref-for-dfn-last-update-check-time-9">(2)</a>
66206630
</ul>
66216631
</aside>
66226632
<aside class="dfn-panel" data-for="dfn-uninstalling-flag">

0 commit comments

Comments
 (0)