Copyright © 2021 W3C ® ( MIT , ERCIM , Keio , Beihang ). W3C liability , trademark and permissive document license rules apply.
This specification defines an interface for web applications to access the complete timing information for navigation of a document.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
Navigation Timing 2 replaces the first version of [ NAVIGATION-TIMING ] and includes the following changes:
This document was published by the Web Performance Working Group as an Editor's Draft.
GitHub
Issues
are
preferred
for
discussion
of
this
specification.
Alternatively,
you
can
send
comments
to
our
mailing
list.
Please
send
them
to
public-web-perf@w3.org
(
subscribe
,
archives
)
with
[NavigationTiming]
at
the
start
of
your
email's
subject.
Publication as an Editor's Draft does not imply endorsement by the W3C Membership.
This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the W3C Patent Policy . W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy .
This document is governed by the 15 September 2020 W3C Process Document .
This section is non-normative.
Accurately measuring performance characteristics of web applications is an important aspect of making web applications faster. While JavaScript-based mechanisms, such as the one described in [ JSMEASURE ], can provide comprehensive instrumentation for user latency measurements within an application, in many cases, they are unable to provide a complete or detailed end-to-end latency picture. For example, the following JavaScript shows a naive attempt to measure the time it takes to fully load a page:
<html>
<head>
<script type="text/javascript">
var start = new Date().getTime();
function onLoad() {
var now = new Date().getTime();
var latency = now - start;
alert("page loading time: " + latency);
}
</script>
</head>
<body onload="onLoad()">
<!- Main page body goes from here. -->
</body>
</
html
>
The above script calculates the time it takes to load the page after the first bit of JavaScript in the head is executed, but it does not give any information about the time it takes to get the page from the server, or the initialization lifecycle of the page.
This
specification
defines
the
PerformanceNavigationTiming
interface
which
participates
in
the
[
PERFORMANCE-TIMELINE-2
]
to
store
and
retrieve
high
resolution
performance
metric
data
related
to
the
navigation
of
a
document.
As
the
PerformanceNavigationTiming
interface
uses
[
HR-TIME-2
],
all
time
values
are
measured
with
respect
to
the
time
origin
of
the
Window
object.
For
example,
if
we
know
that
the
response
end
occurs
100ms
after
the
start
of
navigation,
the
PerformanceNavigationTiming
data
could
look
like
so:
startTime: 0.000 // start time of the navigation request
responseEnd
:
100.000
//
high
resolution
time
of
last
received
byte
The
following
script
shows
how
a
developer
can
use
the
PerformanceNavigationTiming
interface
to
obtain
accurate
timing
data
related
to
the
navigation
of
the
document:
<script>
function showNavigationDetails() {
// Get the first entry
const [entry] = performance.getEntriesByType("navigation");
// Show it in a nice table in the developer console
console.table(entry.toJSON());
}
</script>
<
body
onload
=
"showNavigationDetails()"
>
The
construction
"a
Foo
object",
where
Foo
is
actually
an
interface,
is
sometimes
used
instead
of
the
more
accurate
"an
object
implementing
the
interface
Foo
.
The term navigation refers to the act of navigating .
The term current document refers to the document associated with the Window object's newest Document object .
The term JavaScript is used to refer to ECMA262, rather than the official term ECMAScript, since the term JavaScript is more widely known. [ ECMASCRIPT ]
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 current time 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 [ HR-TIME-2 ] specification.
PerformanceNavigationTiming
interface.
Attributes
in
parenthesis
indicate
that
they
may
not
be
available
for
navigations
involving
documents
from
different
origins
.
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in: