Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 1 | # 103 Early Hints |
| 2 | |
| 3 | Contact: early-hints-experiment@chromium.org |
| 4 | |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 5 | As of version 95, Chrome experimentally supports |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 6 | [Early Hints](https://datatracker.ietf.org/doc/html/rfc8297). |
Kenichi Ishibashi | 6d43eb85 | 2022-04-20 02:28:54 | [diff] [blame] | 7 | Early Hints enable browsers to preload subresources or preconnect to servers |
| 8 | before the main response is served. See the |
| 9 | [explainer](https://github.com/bashi/early-hints-explainer/blob/main/explainer.md) |
| 10 | how it works. |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 11 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 12 | Currently Chrome is running A/B testing in the field to evaluate the performance |
| 13 | impact of Early Hints. Chrome also provides some ways to opt-in Early Hints for |
| 14 | web developers who want to try the feature. This document describes the status |
| 15 | of the current implementation and how to enable Early Hints support. |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 16 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 17 | ## What’s supported |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 18 | |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 19 | Chrome supports [preload](https://w3c.github.io/preload/) and |
| 20 | [preconnect](https://w3c.github.io/resource-hints/#dfn-preconnect) in |
Kenichi Ishibashi | 6d43eb85 | 2022-04-20 02:28:54 | [diff] [blame] | 21 | Early Hints for top-level frame navigation. |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 22 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 23 | ## What’s not supported |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 24 | |
Kenichi Ishibashi | 6d43eb85 | 2022-04-20 02:28:54 | [diff] [blame] | 25 | To reduce security and privacy implications, the HTML and Fetch living standards |
| 26 | have some restrictions on when Early Hints can be handled. Chrome ignores Early |
| 27 | Hints sent in the following situations to comply these specifications. |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 28 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 29 | * Early Hints sent on subresource requests |
| 30 | * Early Hints sent on iframe navigation |
| 31 | * Early Hints sent on HTTP/1.1 or earlier |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 32 | |
Kenichi Ishibashi | 6d43eb85 | 2022-04-20 02:28:54 | [diff] [blame] | 33 | Chrome ignores the second and following Early Hints responses. Chrome only |
| 34 | handles the first Early Hints response so that Chrome doesn't apply inconsistent |
| 35 | security policies (e.g. Content-Security-Policy). |
| 36 | |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 37 | Chrome doesn’t handle |
| 38 | [dns-prefetch](https://w3c.github.io/resource-hints/#dfn-dns-prefetch) and |
| 39 | [prefetch](https://w3c.github.io/resource-hints/#dfn-prefetch) in Early Hints |
| 40 | yet. We consider supporting them in the future. |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 41 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 42 | ## Activation |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 43 | |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 44 | Early Hints can be enabled by a command line flag, or via |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 45 | [Origin Trial](https://developer.chrome.com/blog/origin-trials/). |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 46 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 47 | ### Using command line flag |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 48 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 49 | Passing the `--enable-features=EarlyHintsPreloadForNavigation` command line flag |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 50 | to Chrome enables Early Hints support. |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 51 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 52 | ### Using Origin Trial |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 53 | |
Kenichi Ishibashi | 6d43eb85 | 2022-04-20 02:28:54 | [diff] [blame] | 54 | **Note**: As of version 98 the origin trial has expired. The Chrome networking |
| 55 | team is preparing to ship the feature and the origin trial may be available |
| 56 | again in the near future until it's fully shipped. |
| 57 | |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 58 | You can opt any page on your origin into Early Hints by |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 59 | [requesting a token for your origin](https://developer.chrome.com/origintrials/#/view_trial/2856408063659737089). |
| 60 | Include the token in both Early Hints and the final response so that Chrome can |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 61 | recognize your pages opted in Early Hints. |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 62 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 63 | ``` |
| 64 | HTTP/1.1 103 Early Hints |
| 65 | Origin-Trial: **your token** |
| 66 | Link: </style.css>; rel="preload"; as="style" |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 67 | Link: <https://cdn.test>; rel="preconnect" |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 68 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 69 | HTTP/1.1 200 OK |
| 70 | Origin-Trial: **your token** |
| 71 | Link: </style.css>; rel="preload"; as="style" |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 72 | Link: <https://cdn.test>; rel="preconnect" |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 73 | Content-Type: text/html; charset=utf-8 |
Hiroki Nakagawa | 0c9ee9f9 | 2020-10-16 02:46:56 | [diff] [blame] | 74 | |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 75 | <!DOCTYPE html> |
| 76 | ... |
| 77 | ``` |
| 78 | |
Eric Lawrence [MSFT] | 694be82 | 2021-09-03 23:34:22 | [diff] [blame] | 79 | `<meta http-equiv="origin-trial" content="**your token**">` also works for the |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 80 | final response but doesn’t work for Early Hints since Early Hints cannot convey |
| 81 | a response body. |
| 82 | |
Kenichi Ishibashi | cdbd1ec9e | 2021-09-03 00:24:47 | [diff] [blame] | 83 | ### Checking Early Hints preload is working |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 84 | |
| 85 | If a resource is preloaded by Early Hints, the corresponding |
| 86 | [PerformanceResourceTiming](https://w3c.github.io/resource-timing/#sec-performanceresourcetiming) |
| 87 | object reports `initiatorType` is "early-hints". |
| 88 | ``` |
Eric Lawrence [MSFT] | 694be82 | 2021-09-03 23:34:22 | [diff] [blame] | 89 | performance.getEntriesByName('https://a.test/style.css')[0].initiatorType |
Kenichi Ishibashi | 7e394ecd | 2021-08-24 07:28:24 | [diff] [blame] | 90 | // => 'early-hints' |
| 91 | ``` |
| 92 | |
| 93 | ## Resources |
| 94 | |
| 95 | * [Fastly's test page](https://early-hints.fastlylabs.com/) |