Skip to content

Commit 6634866

Browse files
committed
Document early hints
1 parent 3faea8c commit 6634866

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/technical-details/reference/globals.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,20 @@ The HTTP request listener to be added to the middleware chain. To continue chain
8989

9090
#### `Request`
9191

92-
An implementation of WHATWG [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) class.
92+
An implementation of WHATWG [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) class. This Request is designed to follow the standard as closely as possible, but has some additional properties, methods and behaviors that facilitate its use as a server API:
93+
- `request.url` - This is the resource target of the request, which will includes the full path and query string that comes after the hostname and port in the URL.
94+
- `request.sendEarlyHints(link)` - This sends an early hints response to the client. This is useful for sending link headers to the client before the final response is sent so that browsers can preload resources. This is generally most helpful in a cache resolution function, where you can send hints _if_ the data is not in the cache and is resolving from an origin:
95+
```javascript
96+
class Origin {
97+
async get(request) {
98+
// if we are fetching data from origin, send early hints
99+
this.getContext().requestContext.sendEarlyHints('<link rel="preload" href="/my-resource" as="fetch">');
100+
let response = await fetch(request);
101+
...
102+
}
103+
}
104+
Cache.sourcedFrom(Origin);
105+
```
93106

94107
#### `Response`
95108

0 commit comments

Comments
 (0)