Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 11 additions & 26 deletions files/en-us/web/api/request/destination/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,14 @@ browser-compat: api.Request.destination

{{APIRef("Fetch API")}}{{AvailableInWorkers}}

The **`destination`** read-only
property of the **{{domxref("Request")}}** interface returns a string
describing the type of content being requested.

The string must be one of the `audio`, `audioworklet`,
`document`, `embed`, `fencedframe`, `font`, `frame`,
`iframe`, `image`, `json`, `manifest`, `object`,
`paintworklet`, `report`, `script`, `sharedworker`,
`style`, `track`, `video`, `worker`
or `xslt` strings, or the empty string, which is the default value.

The `destination` is used by the {{Glossary("user agent")}} to, for example,
help determine which set of rules to follow for CORS purposes, or how to navigate any
complicated code paths that affect how specific types of request get handled.

These destinations vary substantially in how they operate. Some are data receptacles,
where the received data is stored for processing later. Others are script-based, in
which case the received data is delivered to a script by calling it and passing the data
along. Script-based destinations include {{HTMLElement("script")}} elements, as well as
any of the {{domxref("Worklet")}}-based destinations
(including subclasses like {{domxref("AudioWorklet")}}), and the
{{domxref("Worker")}}-based destinations, including {{domxref("ServiceWorker")}}
and {{domxref("SharedWorker")}}.
The **`destination`** read-only property of the **{{domxref("Request")}}** interface returns a string describing the type of content being requested.

The string must be one of the `audio`, `audioworklet`, `document`, `embed`, `fencedframe`, `font`, `frame`, `iframe`, `image`, `json`, `manifest`, `object`, `paintworklet`, `report`, `script`, `sharedworker`, `speculationrules`, `style`, `track`, `video`, `worker` or `xslt` strings, or the empty string, which is the default value.

The `destination` is used by the {{Glossary("user agent")}} to, for example, help determine which set of rules to follow for CORS purposes, or how to navigate any complicated code paths that affect how specific types of request get handled.

These destinations vary substantially in how they operate. Some are data receptacles, where the received data is stored for processing later. Others are script-based, in which case the received data is delivered to a script by calling it and passing the data along.
Script-based destinations include {{HTMLElement("script")}} elements, as well as any of the {{domxref("Worklet")}}-based destinations (including subclasses like {{domxref("AudioWorklet")}}), and the {{domxref("Worker")}}-based destinations, including {{domxref("ServiceWorker")}} and {{domxref("SharedWorker")}}.

## Value

Expand Down Expand Up @@ -79,6 +64,8 @@ Possible values are:
- : The target is a service worker.
- `"sharedworker"`
- : The target is a shared worker.
- `"speculationrules"`
- : The target is a [speculation rules](/en-US/docs/Web/API/Speculation_Rules_API) JSON document.
- `"style"`
- : The target is a style
- `"track"`
Expand All @@ -92,9 +79,7 @@ Possible values are:

## Examples

In the following snippet, we create a new request using the
{{domxref("Request.Request", "Request()")}} constructor (for an image file in the same
directory as the script), then save the request's destination:
In the following snippet, we create a new request using the {{domxref("Request.Request", "Request()")}} constructor (for an image file in the same directory as the script), then save the request's destination:

```js
const myRequest = new Request("flowers.jpg");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sidebar: http

The HTTP **`Speculation-Rules`** {{Glossary("response header")}} provides one or more URLs pointing to text resources containing speculation rule JSON definitions. When the response is an HTML document, these rules will be added to the document's speculation rule set. See the [Speculation Rules API](/en-US/docs/Web/API/Speculation_Rules_API) for more information.

The resource file containing the speculation rules JSON can have any valid name and extension, but it must be served with an `application/speculationrules+json` MIME type.
The resource file containing the speculation rules JSON can have any valid name and extension, but it will be requested with a [`destination`](/en-US/docs/Web/API/Request/destination) type of [`speculationrules`](/en-US/docs/Web/API/Request/destination#speculationrules), and must be served with an `application/speculationrules+json` MIME type.

> [!NOTE]
> This mechanism provides an alternative to specifying the JSON definition inside an inline [`<script type="speculationrules">`](/en-US/docs/Web/HTML/Reference/Elements/script/type/speculationrules) element. Specifying an HTTP header is useful in cases where developers are not able to directly modify the document itself.
Expand Down