web.dev LIVE is now over! Head to web.dev/live to watch all the sessions, see top Q&A, and more.

Module: workbox-streams

Methods

concatenate

static

concatenate(sourcePromises) returns Object containing {done: Promise, stream: ReadableStream}

Takes multiple source Promises, each of which could resolve to a Response, a ReadableStream, or a BodyInit.

Returns an object exposing a ReadableStream with each individual stream's data returned in sequence, along with a Promise which signals when the stream is finished (useful for passing to a FetchEvent's waitUntil()).

Parameter

sourcePromises

Array of Promise containing module:workbox-streams.StreamSource

Returns

Object containing {done: Promise, stream: ReadableStream} 

concatenateToResponse

static

concatenateToResponse(sourcePromises, headersInit) returns Object containing {done: Promise, response: Response}

Takes multiple source Promises, each of which could resolve to a Response, a ReadableStream, or a BodyInit, along with a HeadersInit.

Returns an object exposing a Response whose body consists of each individual stream's data returned in sequence, along with a Promise which signals when the stream is finished (useful for passing to a FetchEvent's waitUntil()).

Parameter

sourcePromises

Array of Promise containing module:workbox-streams.StreamSource

headersInit

Optional

HeadersInit

If there's no Content-Type specified, 'text/html' will be used by default.

Returns

Object containing {done: Promise, response: Response} 

isSupported

static

isSupported() returns boolean

This is a utility method that determines whether the current browser supports the features required to create streamed responses. Currently, it checks if ReadableStream can be created.

Returns

boolean true, if the current browser meets the requirements for streaming responses, and false otherwise.

strategy

static

strategy(sourceFunctions, headersInit) returns module:workbox-routing~handlerCallback

A shortcut to create a strategy that could be dropped-in to Workbox's router.

On browsers that do not support constructing new ReadableStreams, this strategy will automatically wait for all the sourceFunctions to complete, and create a final response that concatenates their values together.

Parameter

sourceFunctions

Array of function({event, request, url, params})

An array of functions similar to module:workbox-routing~handlerCallback but that instead return a module:workbox-streams.StreamSource (or a Promise which resolves to one).

headersInit

Optional

HeadersInit

If there's no Content-Type specified, 'text/html' will be used by default.

Returns

module:workbox-routing~handlerCallback 

Abstract type

StreamSource

static

(Response, ReadableStream, or BodyInit)