MDN Web Docs

Syntax

js

clone()

Parameters

None.

Return value

A Response object.

Examples

In our Fetch Response clone example (see Fetch Response clone live) we create a new Request object using the Request() constructor, passing it a JPG path. We then fetch this request using fetch(). When the fetch resolves successfully, we clone it, extract a blob from both responses using two Response.blob calls, create object URLs out of the blobs using URL.createObjectURL(), and display them in two separate <img> elements.

js

const image1 = document.querySelector(".img1");
const image2 = document.querySelector(".img2");
const myRequest = new Request("flowers.jpg");
fetch(myRequest).then((response) => {
  const response2 = response.clone();
  response.blob().then((myBlob) => {
    const objectURL = URL.createObjectURL(myBlob);
    image1.src = objectURL;
  });
  response2.blob().then((myBlob) => {
    const objectURL = URL.createObjectURL(myBlob);
    image2.src = objectURL;
  });
});

Specifications

Specification
Fetch
# ref-for-dom-response-clone①

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗