-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Implement 103 Early Hints #1217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8b3f129
Initial Early Hints work
TartanLlama bb14c71
Implement sendEarlyHint
TartanLlama 06af2b6
Remove debug code
TartanLlama 65eb4b1
Implement early hints
TartanLlama b79db70
Fix sendEarlyHint
TartanLlama 7f2ff02
Documentation
TartanLlama 7ce2c46
Better docs and testing
TartanLlama 953b61e
Format
TartanLlama bcf52c9
Merge branch 'main' into sy/early-hints
TartanLlama a83d482
Merge branch 'main' into sy/early-hints
TartanLlama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
documentation/docs/globals/FetchEvent/prototype/sendEarlyHints.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| hide_title: false | ||
| hide_table_of_contents: false | ||
| pagination_next: null | ||
| pagination_prev: null | ||
| --- | ||
| # FetchEvent.sendEarlyHints() | ||
|
|
||
| The **`sendEarlyHints()`** method allows you to send a [103 Early Hints](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/103) response back to the client which made the incoming request to your application. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```js | ||
| sendEarlyHints(headers) | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| - `headers` | ||
| - : Any headers you want to add to your response, contained | ||
| within a [`Headers`](../../globals/Headers/Headers.mdx) object or object literal of | ||
| [`String`](../../globals/String/String.mdx) key/value pairs. | ||
|
|
||
| ### Return value | ||
|
|
||
| Always returns `undefined`. | ||
|
|
||
| ### Examples | ||
|
|
||
| ```js | ||
| event.sendEarlyHints({ link: '</style.css>; rel=preload; as=style' }); | ||
|
|
||
| event.sendEarlyHints([ | ||
| ['link', '</style.css>; rel=preload; as=style'], | ||
| ['link', '</style2.css>; rel=preload; as=style'] | ||
| ]); | ||
| ``` | ||
25 changes: 25 additions & 0 deletions
25
integration-tests/js-compute/fixtures/app/src/early-hints.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { pass, ok, strictEqual, assertThrows } from './assertions.js'; | ||
| import { routes } from './routes.js'; | ||
|
|
||
| routes.set('/early-hints/manual-response', (event) => { | ||
| event.respondWith( | ||
| new Response(null, { | ||
| status: 103, | ||
| headers: { link: '</style.css>; rel=preload; as=style' }, | ||
| }), | ||
| ); | ||
| event.respondWith(new Response('ok')); | ||
| }); | ||
|
|
||
| routes.set('/early-hints/send-early-hints', (event) => { | ||
| event.sendEarlyHints({ link: '</style.css>; rel=preload; as=style' }); | ||
| event.respondWith(new Response('ok')); | ||
| }); | ||
|
|
||
zkat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| routes.set('/early-hints/send-early-hints-multiple-headers', (event) => { | ||
| event.sendEarlyHints([ | ||
| ['link', '</style.css>; rel=preload; as=style'], | ||
| ['link', '</style2.css>; rel=preload; as=style'], | ||
| ]); | ||
| event.respondWith(new Response('ok')); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.