forked from w3c/resource-timing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
835 lines (744 loc) · 60 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Resource Timing</title>
<script src='//www.w3.org/Tools/respec/respec-w3c-common' async class='remove'></script>
<script class='remove'>
var respecConfig = {
shortName: "resource-timing",
specStatus: "ED",
edDraftURI: "https://w3c.github.io/resource-timing/",
previousPublishedDate: "2014-12-16",
editors: [{
name: "Arvind Jain",
mailto: "[email protected]",
company: "Google Inc.",
w3cid: "45188"
}, {
name: "Todd Reifsteck",
mailto: "[email protected]",
company: "Microsoft Corp.",
w3cid: "76565"
}, {
name: "Jatinder Mann",
mailto: "[email protected]",
company: "Microsoft Corp.",
note: "Until February 2014",
w3cid: "44357"
}, {
name: "Zhiheng Wang",
company: "Google Inc.",
note: "Until July 2012",
w3cid: "43685"
}, {
name: "Anderson Quach",
company: "Microsoft Corp.",
note: "Until March 2011",
w3cid: "45288"
}],
wg: "Web Performance Working Group",
wgURI: "http://www.w3.org/2010/webperf/",
wgPublicList: "public-web-perf",
otherLinks: [{
key: 'Repository',
data: [{
value: 'We are on Github.',
href: 'https://github.com/w3c/resource-timing/'
}, {
value: 'File a bug.',
href: 'https://github.com/w3c/resource-timing/issues'
}, {
value: 'Commit history.',
href: 'https://github.com/w3c/resource-timing/commits/gh-pages/index.html'
}, {
value: 'Tests.',
href: 'https://github.com/w3c/web-platform-tests/tree/master/resource-timing'
}]
}],
wgPatentURI: "http://www.w3.org/2004/01/pp-impl/45211/status"
};
</script>
</head>
<body>
<section id="abstract">
<p>This specification defines an interface for web applications to access
the complete timing information for resources in a document.</p>
</section>
<section id="sotd">
<p>This is a <strong>work in progress</strong> and may change without any
notices. </p>
<p>Please send comments
to <a href="mailto:[email protected]?subject=%5BResourceTiming%5D%20">[email protected]</a>
(<a href="http://lists.w3.org/Archives/Public/public-web-perf/">archived</a>)
with <samp>[ResourceTiming]</samp> at the start of the subject line.</p>
<p id="unstable"><strong class="redNote">Implementers SHOULD be aware that this document is not
stable.</strong> Implementers who are not taking part in the discussions
are likely to find the specification changing out from under them in
incompatible ways. Vendors interested in implementing this document
before it eventually reaches the Candidate Recommendation stage SHOULD
join the aforementioned mailing lists and take part in the discussions.</p>
</section>
<section id="introduction" class='informative'>
<h2>Introduction</h2>
<p>
User latency is an important quality benchmark for Web Applications. While
JavaScript-based mechanisms can provide comprehensive instrumentation for
user latency measurements within an application, in many cases, they are
unable to provide a complete end-to-end latency picture. While Navigation Timing 2 [[navigation-timing-2]] addresses
part of the problem by providing timing information associated with a
navigation, this document introduces the <a href="#resource-timing">ResourceTiming</a>
interface to allow JavaScript mechanisms to collect complete timing
information related to resources on a document.
</p>
<p>For example, the following JavaScript shows a simple attempt to
measure the time it takes to fetch a resource:</p>
<pre class='example highlight'>
<!doctype html>
<html>
<head>
</head>
<body onload="loadResources()">
<script>
function loadResources()
{
var start = new Date().getTime();
var image1 = new Image();
var resourceTiming = function() {
var now = new Date().getTime();
var latency = now - start;
alert("End to end resource fetch: " + latency);
};
image1.onload = resourceTiming;
image1.src = 'http://www.w3.org/Icons/w3c_main.png';
}
</script>
<img src="http://www.w3.org/Icons/w3c_home.png">
</body>
</html>
</pre>
<p>Though this script can measure the time it takes to fetch a resource,
it cannot break down the time spent in various phases. Further, the script
cannot easily measure the time it takes to fetch resources described in markup.</p>
<p>To address the need for complete information on user experience, this document
introduces the <a href="#performanceresourcetiming">PerformanceResourceTiming</a> interface.
This interface allows JavaScript mechanisms to provide complete client-side latency measurements within applications.
With this interface, the previous example can be modified to measure a user's
perceived load time of a resource.
</p>
<p>The following script calculates the amount of time it takes to fetch every resource in the
page, even those defined in markup. This example assumes
that this page is hosted on http://www.w3.org.
One could further measure the amount of time it takes in every phase of fetching a resource
with the <a href="#performanceresourcetiming">PerformanceResourceTiming</a> interface.
</p>
<pre class='example highlight'>
<!doctype html>
<html>
<head>
</head>
<body onload="loadResources()">
<script>
function loadResources()
{
var image1 = new Image();
image1.onload = resourceTiming;
image1.src = 'http://www.w3.org/Icons/w3c_main.png';
}
function resourceTiming()
{
var resourceList = window.performance.getEntriesByType("resource");
for (i = 0; i < resourceList.length; i++)
{
if (resourceList[i].initiatorType == "img")
{
alert("End to end resource fetch: "+ resourceList[i].responseEnd - resourceList[i].startTime);
}
}
}
</script>
<img id="image0" src="http://www.w3.org/Icons/w3c_home.png">
</body>
</html>
</pre>
</section>
<section id="conformance">
<p>Requirements phrased in the imperative as part of algorithms (such as
"strip any leading space characters" or "return false and abort these steps")
are to be interpreted with the meaning of the key word ("MUST", "SHOULD",
"MAY", etc) used in introducing the algorithm. </p>
<p>Some conformance requirements are phrased as requirements on attributes,
methods or objects. Such requirements are to be interpreted as requirements
on user agents. </p>
<p>Conformance requirements phrased as algorithms or specific steps may be
implemented in any manner, so long as the end result is equivalent. (In
particular, the algorithms defined in this specification are intended to be
easy to follow, and not intended to be performant.) </p>
<p>The IDL fragments in this specification must be interpreted as
required for <a href='http://www.w3.org/TR/WebIDL/#dfn-conforming-idl-fragment'>conforming IDL fragments</a>, as described in the Web IDL
specification. [[!WebIDL]]</p>
</section>
<section id="terminology">
<h2>Terminology</h2>
<p>The construction "a <code title="">Foo</code> object", where <code
title="">Foo</code> is actually an interface, is sometimes used instead of
the more accurate "an object implementing the interface <code
title="">Foo</code>". </p>
<p>The term DOM is used to refer to the API set made available to scripts in
Web applications, and does not necessarily imply the existence of an actual
<code>Document</code> object or of any other <code>Node</code> objects as
defined in the DOM specification. [[DOM]]
</p>
<p>A DOM attribute is said to be <em>getting</em> when its value is being
retrieved (such as by author script), and is said to be <em>setting</em> when
a new value is assigned to it.</p>
<p>The term "JavaScript" is used to refer to ECMA262, rather than the
official term ECMAScript, since the term JavaScript is more widely known. [[ECMA-262]]
</p>
<p>
Throughout this work, all time values are measured in milliseconds since the start of
navigation of the document. For example, the start of navigation of the document
occurs at time 0. The term <i>current time</i> refers to the number of milliseconds
since the start of navigation of the document until the current moment in time.
This definition of time is based on the High Resolution Time specification
[[HR-TIME]] and is different
from the definition of time used in the Navigation Timing specification
[[NAVIGATION-TIMING]],
where time is measured in milliseconds since midnight of January 1, 1970 (UTC).
</p>
</section>
<section id="resource-timing">
<h2>Resource Timing</h2>
<section id="introduction-1" class='informative'>
<h3>Introduction</h3>
<p>
The <a href="#performanceresourcetiming">PerformanceResourceTiming</a>
interface facilitates timing measurement of downloadable resources. For example, this interface is available for
<a href="http://www.w3.org/TR/XMLHttpRequest/#interface-xmlhttprequest">XMLHttpRequest</a> objects [[XMLHttpRequest]], HTML
elements [[HTML5]] such as
<a href="http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element">iframe</a>,
<a href="http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element">img</a>,
<a href="http://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a>,
<a href="http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element">object</a>,
<a href="http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element">embed</a>,
and <a href="http://www.w3.org/TR/html5/document-metadata.html#the-link-element">link</a>
with the link type of
<a href="http://www.w3.org/TR/html5/links.html#link-type-stylesheet">stylesheet</a>,
and SVG elements [[SVG11]] such
as <a href="http://www.w3.org/TR/SVG11/struct.html#SVGElement">svg</a>.
</p>
<p>The term "resource" is used to refer to these elements and any other user-initiated fetches throughout this specification.</p>
</section>
<section id="resources-included">
<h3>Resources Included in the <code><a href="#performanceresourcetiming">PerformanceResourceTiming</a></code> Interface</h3>
<p>All resources <a title='fetch' href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetched</a> by the current <a href="http://www.w3.org/TR/html5/browsers.html#browsing-context">browsing</a> [[!HTML5]] or worker [[!WORKERS]] context's MUST be included as <a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a> of the relevant context. Resources that are retrieved from <a href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant application caches</a> or local resources MUST be included as <a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a> ([[!performance-timeline]]). Resources for which the <a title='fetch' href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> was initiated, but was later aborted (e.g. due to a network error) MUST be included as <a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a> and MUST contain initialized attribute values for processed substeps of the <a href="#processing-model">processing model</a>.</p>
<p>The rest of this section is non-normative.</p>
<p>
Examples:</p>
<ul>
<li>If the same canonical URL is used as the <code>src</code> attribute of two HTML <code>IMG</code> elements,
the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource initiated by the first HTML <code>IMG</code> element SHOULD
be included as a <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
The user agent might not re-request the URL for the second HTML <code>IMG</code> element, instead using the existing download it initiated for the first HTML <code>IMG</code> element.
In this case, the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource by the first
<code>IMG</code> element would be the only occurrence in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
</li>
<li>If the <code>src</code> attribute of a HTML <code>IMG</code> element is changed via script, both the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the original resource as well
as the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the new URL would be included as <a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects in
the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
</li>
<li>
If an HTML <code>IFRAME</code> element is added via markup without specifying a <code>src</code> attribute, the user agent may load the <code>about:blank</code> document for the <code>IFRAME</code>. If at a later time the <code>src</code> attribute is changed dynamically via script, the user agent may
<a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> the new URL resource for the <code>IFRAME</code>. In this case, only the
<a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the new URL would be included
as a <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
</li>
<li>
If an <code>XMLHttpRequest</code> is generated twice for the same canonical URL, both <a title='fetch' href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetches</a> of the resource would be
included as a <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
This is because the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource for the second <code>XMLHttpRequest</code> cannot reuse the download issued for the first <code>XMLHttpRequest</code>.
</li>
<li>
If an HTML <code>IFRAME</code> element is included on the page, then only the resource requested by <code>IFRAME</code> <code>src</code> attribute is included
as a <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
Sub-resources requested by the <code>IFRAME</code> document will be included in the <code>IFRAME</code> document's <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a> and not the parent
document's <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
</li>
<li>
If an HTML <code>IMG</code> element has a <code><a href="https://tools.ietf.org/html/rfc2397">data: URI</a></code> as its source [[!RFC2397]], then this resource will not
be included as a <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
By definition <code><a href="https://tools.ietf.org/html/rfc2397">data: URI</a></code> contains embedded data and does not require a <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a>.
</li>
<li>
If a resource <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> was aborted due to a networking error (e.g. DNS, TCP, or TLS error), then the fetch would be included as a <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a> with initialized attribute values up to the point of failure - e.g. a TCP handshake error should report DNS timestamps for the request, and so on.
</li>
<li>
If a resource <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> is aborted because it failed a fetch precondition (e.g. mixed content, CORS restriction, CSP policy, etc), then this resource will not be included as a <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
</li>
</ul>
<p>
The user agent MAY choose to limit how many resources are included as
<a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
The recommended minimum number of <a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects is 150, though this may be changed by the user agent.
<a href="#widl-Performance-setResourceTimingBufferSize-void-unsigned-long-maxSize"><code>setResourceTimingBufferSize</code></a>
can be called to request a change to this limit.
</p>
</section>
<section id="performanceresourcetiming">
<h3>The <code>PerformanceResourceTiming</code> Interface</h3>
<p>
The <a href="#performanceresourcetiming">PerformanceResourceTiming</a> interface participates in the
<a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a> and extends the following attributes of the
<a href="http://www.w3.org/TR/performance-timeline/#performanceentry">PerformanceEntry</a> interface:</p>
<dl class='attributes'>
<dt id='widl-PerformanceResourceTiming-name'><code>name</code></dt>
<dd>
This attribute MUST return the <a href="http://www.w3.org/TR/html5/infrastructure.html#resolve-a-url">resolved URL</a> of the
requested resource. This attribute MUST NOT change even if the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> redirected to a different URL.
</dd>
<dt id='widl-PerformanceResourceTiming-entryType'><code>entryType</code></dt>
<dd>The <code id="entryType-attribute">entryType</code> attribute MUST return the DOMString "<code id="perf-resource">resource</code>".</dd>
<dt id='widl-PerformanceResourceTiming-startTime'><code>startTime</code></dt>
<dd>The <code id="startTime-attribute">startTime</code> attribute MUST return a <a href="http://www.w3.org/TR/hr-time/#domhighrestimestamp">DOMHighResTimeStamp</a> [[!HR-TIME]]
with the time immediately before the user agent starts to queue the resource for <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a>.
If there are HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>
when fetching the resource, and if all the redirects or equivalent are from the <a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a> as the current
document or the <a href="#timing-allow-check">timing allow check</a> algorithm passes, this attribute MUST return the same value as <a href="#widl-PerformanceResourceTiming-redirectStart">redirectStart</a>.
Otherwise, this attribute MUST return the same value as <a href="#widl-PerformanceResourceTiming-fetchStart">fetchStart</a>.</dd>
<dt id='widl-PerformanceResourceTiming-duration'><code>duration</code></dt>
<dd>The <code id="duration-attribute">duration</code> attribute MUST return a <a href="http://www.w3.org/TR/hr-time/#domhighrestimestamp">DOMHighResTimeStamp</a>
equal to the difference between <a href="#widl-PerformanceResourceTiming-responseEnd">responseEnd</a> and <a href="#startTime-attribute">startTime</a>, respectively.</dd>
</dl>
<dl title='[Exposed=(Window,Worker)] interface PerformanceResourceTiming : PerformanceEntry' class='idl'>
<dt>readonly attribute DOMString initiatorType</dt>
<dd>
<p>If the initiator is an <code><a href="http://www.w3.org/TR/dom/#concept-element">element</a></code>, on getting, the <code><a href="#widl-PerformanceResourceTiming-initiatorType">initiatorType</a></code> attribute MUST return a DOMString with the same value as the <code><a href="http://www.w3.org/TR/dom/#concept-element-local-name">localName</a></code> of that
<code><a href="http://www.w3.org/TR/dom/#concept-element">element</a></code> [[!DOM]].</p>
<p>If the initiator is a CSS resource downloaded by the <code><a href="http://www.w3.org/TR/css-syntax-3/#consume-a-url-token">url()</a></code> syntax [[!CSS-SYNTAX-3]], such as <code>@import url()</code> or <code>background: url()</code>,
on getting, the <code><a href="#widl-PerformanceResourceTiming-initiatorType">initiatorType</a></code> attribute MUST return the DOMString <code>"css"</code>.</p>
<p>If the initiator is an XMLHttpRequest object [[!XMLHttpRequest]], on getting, the <code><a href="#widl-PerformanceResourceTiming-initiatorType">initiatorType</a></code> attribute MUST return the DOMString <code>"xmlhttprequest"</code>.</p>
</dd>
<dt>readonly attribute DOMString nextHopProtocol</dt>
<dd>
<p>This attribute MUST return the network protocol used to fetch the resource, as identified by the ALPN Protocol ID [[!RFC7301]]. When a proxy is configured, if a tunnel connection is established then this attribute MUST return the ALPN Protocol ID of the tunneled protocol, otherwise it MUST return the ALPN Protocol ID of the first hop to the proxy.</p>
<p>In order to have precisely one way to represent any ALPN protocol ID, the following additional constraints apply: octets in the ALPN protocol MUST NOT be percent-encoded if they are valid token characters except "%", and when using percent-encoding, uppercase hex digits MUST be used.</p>
<p>Note that this attribute is intended to identify the network protocol in use for the fetch regardless of how it was actually negotiated; that is, even if ALPN is not used to negotiate the network protocol, this attribute still uses the ALPN Protocol ID's to indicate the protocol in use.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp workerStart</dt>
<dd>If the current browsing or worker context's have an <a href="http://www.w3.org/TR/service-workers/#dfn-containing-service-worker-registration">active worker</a> ([[!SERVICE-WORKERS]]), this attribute MUST return the time immediately before the user agent <a href="http://www.w3.org/TR/service-workers/#service-worker-concept">runs the worker</a> required to service the request, or if the worker is available, the time immediately before the user agent <a href="http://www.w3.org/TR/service-workers/#on-fetch-request-algorithm">fires an event named `fetch`</a> at the <a href="http://www.w3.org/TR/service-workers/#dfn-active-worker">active worker</a>. Otherwise, if there is no active worker this attribute MUST return zero.</dd>
<dt>readonly attribute DOMHighResTimeStamp redirectStart</dt>
<dd>
<p>If there are HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>
when <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a> the resource and if all the redirects or equivalent are from the <a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a> as the current document,
this attribute MUST return the <a href="#widl-PerformanceResourceTiming-fetchStart">starting time</a> of the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> that initiates the redirect.</p>
<p>If there are HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>
when <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a> the resource and if any of the redirects are not from the <a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a> as the current document,
but the <a href="#timing-allow-check">timing allow check</a> algorithm passes for each redirected resource, this attribute MUST
return the <a href="#widl-PerformanceResourceTiming-fetchStart">starting time of the fetch</a> that initiates the redirect.
Otherwise, this attribute MUST return zero. </p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp redirectEnd</dt>
<dd>
<p>If there are HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>
when <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a> the resource and if all the redirects or equivalent are from the <a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a> as the current document,
this attribute MUST return the time immediately after receiving the last byte of the response of the last redirect.</p>
<p>If there are HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>
when <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a> the resource and if any of the redirects are not from the <a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a> as the current document,
but the <a href="#timing-allow-check">timing allow check</a> algorithm passes for each redirected resource, this attribute MUST return the
time immediately after receiving the last byte of the response of the last redirect.
Otherwise, this attribute MUST return zero. </p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp fetchStart</dt>
<dd>
<p>If there are no HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>,
this attribute MUST return the time immediately before the user agent starts to <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> the resource.</p>
<p>If there are HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>,
this attribute MUST return the time immediately before the user agent starts to <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> the final resource in the redirection.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp domainLookupStart</dt>
<dd>
<p>This attribute MUST return the time immediately before the user agent starts
the domain name lookup for the resource.
If a <a href="https://tools.ietf.org/html/rfc7230#section-6.3">persistent
connection</a> [[!RFC7230]] is used or the resource
is retrieved from <a href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant
application caches</a> or local resources, this attribute MUST return the same
value as <a href="#widl-PerformanceResourceTiming-fetchStart">fetchStart</a>. </p>
<p>
If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document,
<a href="#widl-PerformanceResourceTiming-domainLookupStart">domainLookupStart</a> MUST return
zero unless the <a href="#timing-allow-check">timing allow check</a> algorithm passes.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp domainLookupEnd</dt>
<dd>
<p>This attribute MUST return the time immediately after the user agent finishes
the domain name lookup for the resource.
If a <a href="https://tools.ietf.org/html/rfc7230#section-6.3">persistent
connection</a> [[!RFC7230]] is used or the resource
is retrieved from <a href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant
application caches</a> or local resources, this attribute MUST return the same
value as <a href="#widl-PerformanceResourceTiming-fetchStart">fetchStart</a>. </p>
<p>If the user agent has the domain information in cache,
domainLookupStart and domainLookupEnd represent the times when the user agent
starts and ends the domain data retrieval from the cache. </p>
<p>
If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document,
<a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a> MUST return
zero unless the <a href="#timing-allow-check">timing allow check</a> algorithm passes.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp connectStart</dt>
<dd>
<p>This attribute MUST return the time immediately before the user agent start
establishing the connection to the server to retrieve the resource.
If a <a href="https://tools.ietf.org/html/rfc7230#section-6.3">persistent
connection</a> [[!RFC7230]] is used or the resource is retrieved from <a
href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant
application caches</a> or local resources, this attribute MUST return value of
<a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>.</p>
<p>
If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document,
<a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a> MUST return
zero unless <a href="#timing-allow-check">timing allow check</a> algorithm passes.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp connectEnd</dt>
<dd>
<p>This attribute MUST return the time immediately after the user agent finishes
establishing the connection to the server to retrieve the resource.
If a <a href="https://tools.ietf.org/html/rfc7230#section-6.3">persistent
connection</a> [[!RFC7230]] is used or the resource is retrieved from <a
href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant
application caches</a> or local resources, this attribute MUST return the value of
<a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>.</p>
<p>If the transport connection fails and the user agent reopens a connection,
<a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a> and <a
href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a> SHOULD return the corresponding
values of the new connection. </p>
<p><a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a> MUST include the time interval to
establish the transport connection, as well as other time intervals such as SSL handshake and SOCKS authentication. </p>
<p>
If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document,
<a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a> MUST return
zero unless the <a href="#timing-allow-check">timing allow check</a> algorithm passes.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp secureConnectionStart</dt>
<dd>
<p>
When a secure transport is used, this attribute MUST return the time immediately before the user agent starts the handshake process to secure the current connection.
If a secure transport is not used, this attribute MUST return zero.
If a <a href="https://tools.ietf.org/html/rfc7230#section-6.3">persistent connection</a> [[!RFC7230]] is used or the resource is retrieved from
<a href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant application caches</a> or local resources,
this attribute MUST return value of <a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>.
</p>
<p>
If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document,
<a href="#widl-PerformanceResourceTiming-secureConnectionStart">secureConnectionStart</a> MUST return
zero unless the <a href="#timing-allow-check">timing allow check</a> algorithm passes.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp requestStart</dt>
<dd>
<p>This attribute MUST return the time immediately before the user agent
starts requesting the resource from the server, or from
<a href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>
relevant application caches</a> or from local resources.</p>
<p>If the transport connection fails after a request is sent and the user
agent reopens a connection and resend the request, <a
href="#widl-PerformanceResourceTiming-requestStart">requestStart</a> MUST return the corresponding values
of the new request.</p>
<p>
If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document,
<a href="#widl-PerformanceResourceTiming-requestStart">requestStart</a> MUST return
zero unless the <a href="#timing-allow-check">timing allow check</a> algorithm passes.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp responseStart</dt>
<dd>
<p>This attribute MUST return the time immediately after the user agent receives
the first byte of the response from the server, or from <a
href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant
application caches</a> or from local resources.</p>
<p>
If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document,
<a href="#widl-PerformanceResourceTiming-responseStart">responseStart</a> MUST return
zero unless the <a href="#timing-allow-check">timing allow check</a> algorithm passes.</p>
</dd>
<dt>readonly attribute DOMHighResTimeStamp responseEnd</dt>
<dd>
<p>This attribute MUST return the time immediately after the user agent receives the last byte of the resource or immediately before the transport connection is closed, whichever comes first. The resource here can be received either from the server, <a
href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache" title='relevant application cache'>relevant application caches</a> or from local resources.</p>
</dd>
<dt>readonly attribute unsigned short transferSize</dt>
<dd>
<p>This attribute MUST return the size, in octets received by the client, consumed by the response header fields and the response <a href="http://httpwg.github.io/specs/rfc7230.html#message.body">payload body</a> [[!RFC7230]].</p>
<p>This attribute SHOULD include HTTP overhead (such as HTTP/1.1 chunked encoding and whitespace around header fields, including newlines, and <a href='https://tools.ietf.org/html/draft-ietf-httpbis-http2-16'>HTTP/2</a> frame overhead, along with other server-to-client frames on the same stream), but SHOULD NOT include lower-layer protocol overhead (such as TLS or TCP). If there are HTTP redirects or <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a> when navigating and if all the redirects or equivalent are from the same <a href="https://tools.ietf.org/html/rfc6454#section-4">origin</a> [[!RFC6454]], this attribute SHOULD include the HTTP overhead of incurred redirects.</p>
</dd>
<dt>readonly attribute unsigned short encodedBodySize</dt>
<dd>
<p>This attribute MUST return the size, in octets received by the client, of the <a href="http://httpwg.github.io/specs/rfc7230.html#message.body">payload body</a> [[!RFC7230]], prior to removing any applied <a href="http://httpwg.github.io/specs/rfc7231.html#data.encoding">content-codings</a> [[!RFC7231]].</p>
</dd>
<dt>readonly attribute unsigned short decodedBodySize</dt>
<dd>
<p>This attribute MUST return the size, in octets received by the client, of the <a href="http://httpwg.github.io/specs/rfc7230.html#message.body">message body</a> [[!RFC7230]], after removing any applied <a href="http://httpwg.github.io/specs/rfc7231.html#data.encoding">content-codings</a> [[!RFC7231]].</p>
</dd>
<dt>serializer = { inherit, attribute }</dt>
</dl>
</section>
<section id="extensions-performance-interface">
<h3>Extensions to the <code>Performance</code> Interface</h3>
<dl class="idl" title='partial interface Performance'>
<dt>void clearResourceTimings()</dt>
<dd>
<p>The method <code>clearResourceTimings</code> clears the buffer used to store the current
list of <a href="#performanceresourcetiming">PerformanceResourceTiming</a> resources.
</p>
</dd>
<dt>void setResourceTimingBufferSize(unsigned long maxSize)</dt>
<dd>
<p>The <code>setResourceTimingBufferSize</code> method, when invoked, MUST set the maximum number of <a href="#performanceresourcetiming">PerformanceResourceTiming</a> resources that may be stored in
the buffer to the value of the maxSize parameter. The buffer is considered to be full if the number of entries in it is greater than or equal to <code>maxSize</code>.</p>
<p>If this method is not called, the user agent SHOULD store at least 150 <a href="#performanceresourcetiming">PerformanceResourceTiming</a> resources in the buffer, unless otherwise specified by the user agent.</p>
<p>If the <code>maxSize</code> parameter is less than the number of elements currently stored in the buffer, no elements in the buffer are to be removed and the user agent MUST NOT fire the <code>resourcetimingbufferfull</code> event.</p>
<dl class="parameters">
<dt>unsigned long maxSize</dt>
<dd>
<p>The maxSize parameter sets the maximum number of <a href="#performanceresourcetiming">PerformanceResourceTiming</a> resources that will be stored in the buffer.</p>
</dd>
</dl>
</dd>
<dt>attribute EventHandler onresourcetimingbufferfull</dt>
<dd>
<p>
The event handler for the <code>resourcetimingbufferfull</code> event. Immediately after the buffer used to store the list of <a href="#performanceresourcetiming">PerformanceResourceTiming</a>
resources becomes full, the User Agent MUST fire a simple event named <code>resourcetimingbufferfull</code> that bubbles, isn't cancelable, has no default action, at the
<a href="http://www.w3.org/TR/navigation-timing-2/#performance">Performance</a> object.
</p>
</dd>
</dl>
</section>
<section id="cross-origin-resources">
<h3>Cross-origin Resources</h3>
<p>
Cross-origin resources MUST be included as <a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects in the <a href="http://www.w3.org/TR/performance-timeline/#sec-performance-timeline">Performance Timeline</a>.
If the <a href="#timing-allow-check">timing allow check</a> algorithm fails for a cross-origin resource, these attributes of its <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object
MUST be set to zero: <a href="#widl-PerformanceResourceTiming-redirectStart">redirectStart</a>, <a href="#widl-PerformanceResourceTiming-redirectEnd">redirectEnd</a>,
<a href="#widl-PerformanceResourceTiming-domainLookupStart">domainLookupStart</a>, <a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>, <a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a>,
<a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a>, <a href="#widl-PerformanceResourceTiming-requestStart">requestStart</a>, <a href="#widl-PerformanceResourceTiming-responseStart">responseStart</a>
and <a href="#widl-PerformanceResourceTiming-secureConnectionStart">secureConnectionStart</a>.
</p>
<p>
The term <dfn id="cross-origin">cross-origin</dfn> is used to mean non
<a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a>.
</p>
<p>
Server-side applications may return the <code><a href="#timing-allow-origin">Timing-Allow-Origin</a></code> HTTP response header
to allow the User Agent to fully expose, to the document origin(s) specified, the
values of attributes that would have been zero due to the cross-origin
restrictions previously specified in this section. </p>
<section id="timing-allow-origin">
<h4><code>Timing-Allow-Origin</code> Response Header</h4>
<dl class="attributes">
<dt id="http-timing-allow-origin"><code>Timing-Allow-Origin</code></dt>
<dd>
<p>The <dfn></dfn> header indicates whether a resource's timing can be
shared based by returning the value of the Origin request header in the
response.</p>
<p>ABNF:</p>
<pre>Timing-Allow-Origin = "Timing-Allow-Origin" ":" <a href='https://tools.ietf.org/html/rfc6454#section-7.1'>origin-list-or-null</a> | "*"</pre>
</dd>
</dl>
<p>The <dfn id="timing-allow-check">timing allow check</dfn>
algorithm, which checks whether a cross-origin resource's timing information can be shared with the current document, is as follows:<p>
<ol>
<li><p>If the HTTP response includes zero or more than one
<code><a href="#http-timing-allow-origin">Timing-Allow-Origin</a></code>
header values, return fail and terminate this algorithm.</p></li>
<li><p>If the
<code><a href="#http-timing-allow-origin">Timing-Allow-Origin</a></code>
header value is the "<code>*</code>" character, return pass and terminate this
algorithm.</p></li>
<li><p>If the value of
<code><a href="#http-timing-allow-origin">Timing-Allow-Origin</a></code>
is not a <a href="http://www.w3.org/TR/html5/infrastructure.html#case-sensitive">case-sensitive</a> match for the value of the
<code title="http-origin"><a href="https://tools.ietf.org/html/rfc6454#section-4">origin</a></code> of the current document, return fail and terminate this algorithm.</p></li>
<li><p>Return pass.</p></li>
</ol>
<p class="note">The above algorithm also functions when the
<a href="https://tools.ietf.org/html/rfc6454#section-6.2">ASCII serialization of an origin</a> is
the string "<code>null</code>". Typically, this is the case when there are multiple redirects and the initiator is an XMLHttpRequest object.</p>
<p class="note">In practice the
<code><a href="https://tools.ietf.org/html/rfc6454#section-7.1">origin-list-or-null</a></code> production is
more constrained. Rather than allowing a space-separated list of
<a href="https://tools.ietf.org/html/rfc6454#section-4" title="origin">origins</a>, it is either a
single <a href="https://tools.ietf.org/html/rfc6454#section-4">origin</a> or the string
"<code>null</code>".</p>
</section>
</section>
</section>
<section id="process">
<h2>Process</h2>
<section id="processing-model">
<h3>Processing Model</h3>
<p>The following graph illustrates the timing attributes defined by the PerformanceResourceTiming interface. Attributes underlined may not be available when <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a> resources from different <a href="#same-origin">origins</a>. User agents may perform internal processing in between timings, which allow for non-normative intervals between timings.</p>
<p><img style="width:85%" src="resource-timing-overview-1.png" alt='Resource Timing attributes'></p>
<ol>
<li>Once the <a href="http://www.w3.org/TR/workers/#processing-model">Worker</a> or <a href="http://www.w3.org/TR/html5/browsers.html#create-a-document-object">Window object</a> is created, the user agent MUST create a <a href="http://www.w3.org/TR/performance-timeline/#performanceentrylist">PerformanceEntryList</a>
<i>primary buffer</i> object to store the list
of <a href="#performanceresourcetiming">PerformanceResourceTiming</a> resources.</li>
<li>Set the <i>primary buffer</i> to a size of 150, unless otherwise specified
by the user agent or set by the <a href="#widl-Performance-setResourceTimingBufferSize-void-unsigned-long-maxSize"><code>setResourceTimingBufferSize</code></a> method.
</li>
<li>For each resource <a title='fetch' href="https://fetch.spec.whatwg.org/#concept-fetch">fetched</a> by the current <a href="http://www.w3.org/TR/html5/browsers.html#browsing-context">browsing context</a>, excluding resources fetched by cross-origin stylesheets fetched with <code>no-cors</code> policy, perform the following steps:
<p class="issue">
Above cross-origin exclusion should be defined via Fetch registry: CSS needs to be defined in terms of Fetch and set some kind of "opaque request flag" for no-CORS CSS subresources. In turn, Resource Timing should interface with Fetch registry to surface resource fetch events.
</p>
<ol>
<li id="step-create-object">Create a new <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object and
set <a href="#entryType-attribute">entryType</a> to the DOMString <code>resource</code>.
</li>
<li>Immediately before the user agent starts to queue the resource for retrieval,
record the current time in <a href="#startTime-attribute">startTime</a>, and set <a href="#widl-PerformanceResourceTiming-nextHopProtocol">nextHopProtocol</a> to the empty DOMString.
</li>
<li>Record the initiator of the resource in <a href="#widl-PerformanceResourceTiming-initiatorType">initiatorType</a>.
</li>
<li>Record the <a href="http://www.w3.org/TR/html5/infrastructure.html#resolve-a-url">resolved URL</a> of the requested resource in <a href="#widl-PerformanceResourceTiming-name">name</a>. If there is an <a href="http://www.w3.org/TR/service-workers/#dfn-containing-service-worker-registration">active worker</a> ([[!SERVICE-WORKERS]]) matching the current browsing or worker context's, immediately before the user agent <a href="http://www.w3.org/TR/service-workers/#service-worker-concept">runs the worker</a> record the time as <a href="#widl-PerformanceResourceTiming-workerStart">workerStart</a>, or if the worker is already available, immediately before the <a href="http://www.w3.org/TR/service-workers/#on-fetch-request-algorithm">event named `fetch` is fired</a> at the active worker record the time as <a href="#widl-PerformanceResourceTiming-workerStart">workerStart</a>. Otherwise, if there is no matching <a href="http://www.w3.org/TR/service-workers/#dfn-service-worker-registration">service worker registration</a>, set <a href="#widl-PerformanceResourceTiming-workerStart">workerStart</a> value to zero.</li>
<li id="step-fetch-start">Immediately before a user agent starts the <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching process</a>, record the current time as <a href="#widl-PerformanceResourceTiming-fetchStart">fetchStart</a>. Let <a href="#widl-PerformanceResourceTiming-domainLookupStart">domainLookupStart</a>, <a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>, <a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a> and <a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a> be the same value as <a href="#widl-PerformanceResourceTiming-fetchStart">fetchStart</a>.</li>
<li id="step-collection-start">If the user agent is to reuse the data from another existing or completed <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> initiated from the current document, abort the
remaining steps.
</li>
<li>If <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a> the resource is aborted for any reason, abort the remaining steps. </li>
<li>If the last non-redirected <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> of the resource is not the same origin as the current document
and the <a href="#timing-allow-check">timing allow check</a> algorithm fails, the user agent
MUST set
<a href="#widl-PerformanceResourceTiming-redirectStart">redirectStart</a>,
<a href="#widl-PerformanceResourceTiming-redirectEnd">redirectEnd</a>,
<a href="#widl-PerformanceResourceTiming-domainLookupStart">domainLookupStart</a>,
<a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>,
<a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a>,
<a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a>,
<a href="#widl-PerformanceResourceTiming-requestStart">requestStart</a>,
<a href="#widl-PerformanceResourceTiming-responseStart">responseStart</a> and
<a href="#widl-PerformanceResourceTiming-secureConnectionStart">secureConnectionStart</a>
to zero and go to step <a href="#step-response-end">3.17</a>.
</li>
<li>Let <a href="#widl-PerformanceResourceTiming-domainLookupStart">domainLookupStart</a>,
<a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>,
<a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a> and
<a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a> be the same value as
<a href="#widl-PerformanceResourceTiming-fetchStart">fetchStart</a>.</li>
<li>If the resource is fetched from the <a href="http://www.w3.org/TR/html5/browsers.html#relevant-application-cache">
relevant application cache</a> or local resources, including the <a
href="https://tools.ietf.org/html/rfc7234">HTTP cache</a> [[!RFC7234]],
go to step <a href="#step-request-start">3.15</a>.
</li>
<li>If no domain lookup is required, go to step <a href="#step-connect-start">3.13</a>. Otherwise, immediately before a user agent
starts the domain name lookup, record the time as <a href="#widl-PerformanceResourceTiming-domainLookupStart">domainLookupStart</a>.</li>
<li>Record the time as <a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a> immediately after the
domain name lookup is successfully done. A user agent may need multiple retries before that. If
the domain lookup fails, abort the remaining steps. </li>
<li id="step-connect-start">If a persistent transport connection is used to <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch">fetch</a> the resource,
let <a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a> and <a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a>
be the same value of <a href="#widl-PerformanceResourceTiming-domainLookupEnd">domainLookupEnd</a>. Otherwise, record the time as
<a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a> immediately before initiating the connection to the server and record the time as <a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a> immediately after the connection to the server or the proxy is established. A user agent may need multiple retries before this time. Once connection is established set the value of <a href="#widl-PerformanceResourceTiming-nextHopProtocol">nextHopProtocol</a> to the ALPN ID used by the connection. If a connection can not be established, abort the remaining steps.
</li>
<li>The user agent MUST set the <a href="#widl-PerformanceResourceTiming-secureConnectionStart">secureConnectionStart</a> attribute as follows:
<ol>
<li>When a secure transport is used, the user agent MUST record the
time as <a href="#widl-PerformanceResourceTiming-secureConnectionStart">secureConnectionStart</a>
immediately before the handshake process to secure the connection.
</li>
<li>When a secure transport is not used, the user agent MUST set the
value of <a href="#widl-PerformanceResourceTiming-secureConnectionStart">secureConnectionStart</a> to 0.
</li>
</ol>
</li>
<li id="step-request-start">Immediately before a user agent starts sending the request
for the resource, record the current time as <a href="#widl-PerformanceResourceTiming-requestStart">requestStart</a>.
</li>
<li id="step-response-start">Record the time as <a href="#widl-PerformanceResourceTiming-responseStart">
responseStart</a> immediately after the user agent receives the first byte of the response.
</li>
<li id="step-response-end">Record the time as <a href="#widl-PerformanceResourceTiming-responseEnd">responseEnd</a>
immediately after receiving the last byte of the response.
<ol>
<li>Return to step <a href="#step-connect-start">3.13</a> if the user agent fails to send the request or receive the entire response, and needs to reopen the connection.
<div class="example">
<div class="example-title">EXAMPLE</div>
<p>When <a href="https://tools.ietf.org/html/rfc7230#section-6.3">persistent connection</a>
[[!RFC7230]] is enabled, a user agent may first try to re-use an open connect to
send the request while the connection can be <a href="https://tools.ietf.org/html/rfc7230#section-6.5">asynchronously
closed</a>. In such case, <a href="#widl-PerformanceResourceTiming-connectStart">connectStart</a>, <a href="#widl-PerformanceResourceTiming-connectEnd">connectEnd</a> and
<a href="#widl-PerformanceResourceTiming-requestStart">requestStart</a> SHOULD represent timing information collected over the re-open connection. </p>
</div></li>
<li>Set the value of <a href="#widl-PerformanceResourceTiming-transferSize">transferSize</a>, <a href="#widl-PerformanceResourceTiming-encodedBodySize">encodedBodySize</a>, <a href="#widl-PerformanceResourceTiming-decodedBodySize">decodedBodySize</a> to corresponding values.</li>
</ol>
</li>
<li>Record the difference between <a href="#widl-PerformanceResourceTiming-responseEnd">responseEnd</a> and <a href="#startTime-attribute">startTime</a> in <a href="#duration-attribute">duration</a>.</li>
<li>If the fetched resource results in an HTTP redirect or
<a href="http://www.w3.org/TR/html5/infrastructure.html#concept-http-equivalent-codes" title='HTTP response codes equivalence'>equivalent</a>, then
<ol style="list-style-type:lower-alpha;">
<li>If the current resource and the redirected resource are not from the
<a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a> as the current document,
and the <a href="#timing-allow-check">timing allow check</a> algorithm fails for either resource,
set <a href="#widl-PerformanceResourceTiming-redirectStart">
redirectStart</a> and <a href="#widl-PerformanceResourceTiming-redirectEnd">redirectEnd</a> to 0. Then, return to step <a href="#step-fetch-start">
3.5</a> with the new resource.
</li>
<li>If the value of redirectStart is not set, let it be the value of fetchStart.
</li>
<li>Let redirectEnd be the value of responseEnd.
</li>
<li>Set all the attributes in the <a href="#performanceresourcetiming">
PerformanceResourceTiming</a> object to 0 except
<a href="#startTime-attribute">startTime</a>,
<a href="#widl-PerformanceResourceTiming-redirectStart">redirectStart</a>, <a href="#widl-PerformanceResourceTiming-redirectEnd">
redirectEnd</a>, and <a href="#widl-PerformanceResourceTiming-initiatorType">initiatorType</a>.
</li>
<li>Return to step <a href="#step-fetch-start">3.5</a> with the new resource.
</li>
</ol>
</li>
<li>If the <i>primary buffer</i> is full, discard the <a href="#performanceresourcetiming">PerformanceResourceTiming</a> object,
created in step <a href="#step-create-object">3.1</a>. Otherwise, add it to the <i>primary buffer</i>.
If adding it causes the <i> primary buffer </i> to become full, fire the <a href="#widl-Performance-onresourcetimingbufferfull"><code>resourcetimingbufferfull</code></a> event at the Document.
<ol>
<li>
If the <a href="#widl-Performance-clearResourceTimings-void"><code>clearResourceTimings</code></a> method is called in the event handler for the <a href="#widl-Performance-onresourcetimingbufferfull"><code>resourcetimingbufferfull</code></a> event,
clear all <a href="#performanceresourcetiming">PerformanceResourceTiming</a> objects in the <i>primary buffer</i>.
</li>
<li>
If the <a href="#widl-Performance-setResourceTimingBufferSize-void-unsigned-long-maxSize"><code>setResourceTimingBufferSize</code></a> method is called in the event handler for the <a href="#widl-Performance-onresourcetimingbufferfull"><code>resourcetimingbufferfull</code></a> event,
set the maximum size of the <i>primary buffer</i> to the maxSize parameter. If the maxSize parameter is less than the number of elements currently stored in the buffer, no elements in the buffer are to be removed.
</li>
</ol>
</li>
</ol>
</li>
</ol>
</section>
<section id="monotonic-clock">
<h3>Monotonic Clock</h3>
<p>The value of the timing attributes MUST monotonically increase to ensure timing attributes are not
skewed by adjustments to the system clock while <a href="http://www.w3.org/TR/html5/infrastructure.html#fetch" title='fetch'>fetching</a> the resource. The difference between any two chronologically
recorded timing attributes MUST never be negative. For all resources, including subdocument resources, the user agent MUST
record the system clock at the beginning of the root document navigation and define subsequent timing attributes in
terms of a monotonic clock measuring time elapsed from the beginning of the navigation.
</p>
</section>
</section>
<section id="privacy-security" class='informative'>
<h2>Privacy and Security</h2>
<p>The <a href="#performanceresourcetiming">PerformanceResourceTiming</a> interface exposes timing information for a resource to any web page or worker that has requested that resource. To limit the access to the <a href="#performanceresourcetiming">PerformanceResourceTiming</a> interface, the <a href="https://tools.ietf.org/html/rfc6454#section-5">same origin</a>
policy is enforced by default and certain attributes are set to zero, as described in <a href="#cross-origin-resources"></a>. Resource providers can
explicitly allow all timing information to be collected for a resource by
adding the <a href="#timing-allow-origin">Timing-Allow-Origin</a> HTTP response header, which specifies the
domains that are allowed to access the timing information. </p>
<p>
Statistical fingerprinting is a privacy concern where a malicious web site may determine whether a user has visited a third-party web site by measuring the timing of cache hits and misses of resources in the third-party web site. Though the <a href="#performanceresourcetiming">PerformanceResourceTiming</a> interface gives timing information for resources in a document, the <a href="#cross-origin-resources">cross-origin restrictions</a> prevent making this privacy concern any worse than it is today using the load event on resources to measure timing to determine cache hits and misses.
</p>
</section>
<section class="appendix">
<h2>Acknowledgments</h2>
<p>We would like to sincerely thank Karen Anderson, Darin Fisher, Tony Gentilcore,
Nic Jansma, Kyle Scholz, Jonas Sicking, James Simonsen, Steve Souders,
Annie Sullivan, Sigbjørn Vik, Jason Weber to acknowledge their contributions to this work.</p>
</section>
</body>
</html>