summaryrefslogtreecommitdiffstats
path: root/chromium/docs/early-hints.md
blob: 3d18d07bf7558d02f4b2382b9a0fc909b9f1f525 (plain)
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
# 103 Early Hints

Contact: early-hints-experiment@chromium.org

As of version 95, Chrome experimentally supports
[Early Hints](https://datatracker.ietf.org/doc/html/rfc8297).
Early Hints enable browsers to start preload before the main response is served.
In addition, this can be used with other
[Resource Hints](https://w3c.github.io/resource-hints/) APIs like preconnect.

Currently Chrome is running A/B testing in the field to evaluate the performance
impact of Early Hints. Chrome also provides some ways to opt-in Early Hints for
web developers who want to try the feature. This document describes the status
of the current implementation and how to enable Early Hints support.

## What’s supported

Chrome supports [preload](https://w3c.github.io/preload/) and
[preconnect](https://w3c.github.io/resource-hints/#dfn-preconnect) in
Early Hints for top-level frame navigation. See the
[explainer](https://github.com/bashi/early-hints-explainer/blob/main/explainer.md)
how it works.

## What’s not supported

To reduce security and privacy implications, Chrome ignores Early hints sent in
the following situations.

* Early Hints sent on subresource requests
* Early Hints sent on iframe navigation
* Early Hints sent on HTTP/1.1 or earlier

Chrome doesn’t handle
[dns-prefetch](https://w3c.github.io/resource-hints/#dfn-dns-prefetch) and
[prefetch](https://w3c.github.io/resource-hints/#dfn-prefetch) in Early Hints
yet. We consider supporting them in the future.

## Activation

Early Hints can be enabled by a command line flag, or via
[Origin Trial](https://developer.chrome.com/blog/origin-trials/).

### Using command line flag

Passing the `--enable-features=EarlyHintsPreloadForNavigation` command line flag
to Chrome enables Early Hints support.

### Using Origin Trial

You can opt any page on your origin into Early Hints by
[requesting a token for your origin](https://developer.chrome.com/origintrials/#/view_trial/2856408063659737089).
Include the token in both Early Hints and the final response so that Chrome can
recognize your pages opted in Early Hints.

```
HTTP/1.1 103 Early Hints
Origin-Trial: **your token**
Link: </style.css>; rel="preload"; as="style"
Link: <https://cdn.test>; rel="preconnect"

HTTP/1.1 200 OK
Origin-Trial: **your token**
Link: </style.css>; rel="preload"; as="style"
Link: <https://cdn.test>; rel="preconnect"
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
...
```

`<meta http-equiv="origin-trial" content="**your token**">` also works for the
final response but doesn’t work for Early Hints since Early Hints cannot convey
a response body.

### Checking Early Hints preload is working

If a resource is preloaded by Early Hints, the corresponding
[PerformanceResourceTiming](https://w3c.github.io/resource-timing/#sec-performanceresourcetiming)
object reports `initiatorType` is "early-hints".
```
performance.getEntriesByName('https://a.test/style.css')[0].initiatorType
// => 'early-hints'
```

## Resources

* [Fastly's test page](https://early-hints.fastlylabs.com/)