Web APIs

Cache.prototype.put()

Try the free JavaScript compiler

Stores an eligible request/response pair, consuming the supplied response body; resolves when the operation completes.

Formal Syntax & Structure

javascript syntaxjavascript
cache.put(request, response)

Parameters & Attributes

NameTypeDescription
requestRequest | stringEligible GET request or URL.
responseResponseEligible response to store.

Return Value

Promise<undefined>

Stores an eligible request/response pair, consuming the supplied response body; resolves when the operation completes.

Working Example

Example Snippetjavascript
(async () => {const name="bm-v14-"+crypto.randomUUID();try{const c=await caches.open(name),url=new URL("v14-item",location.href).href,r=new Response("saved");await c.put(url,r.clone());console.log(await r.text(),await (await c.match(url)).text());}finally{await caches.delete(name);}})()
JavaScript Reference