Socket
Socket
Sign inDemoInstall

workbox-streams

Package Overview
Dependencies
2
Maintainers
6
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-streams

A library that makes it easier to work with Streams in the browser.


Version published
Maintainers
6
Weekly downloads
4,064,987
decreased by-9.09%

Weekly downloads

Package description

What is workbox-streams?

The workbox-streams package is part of the Workbox suite of libraries, which are designed to make it easier to build high-quality Progressive Web Apps (PWAs) by providing tools that leverage service workers. Specifically, workbox-streams allows you to efficiently combine multiple strategies for fetching resources, enabling you to use streams to dynamically construct responses within a service worker. This can be particularly useful for scenarios where you want to cache certain parts of a request or dynamically generate content.

What are workbox-streams's main functionalities?

Concatenating responses from multiple sources

This feature allows you to concatenate responses from multiple sources, such as cache or network, into a single response. This is useful for constructing a full page response from separate parts.

import {strategy, concatenate, concatenateToResponse} from 'workbox-streams';

self.addEventListener('fetch', (event) => {
  event.respondWith((async () => {
    const parts = [
      caches.match('/header.html'),
      fetch('/main-content.html'),
      caches.match('/footer.html')
    ];
    return concatenateToResponse(parts);
  })());
});

Using streams to dynamically generate content

This feature demonstrates how you can use streams to dynamically generate content by combining static and dynamic parts of a response. This is particularly useful for injecting dynamic content into a static template.

import {strategy, concatenate, concatenateToResponse} from 'workbox-streams';

self.addEventListener('fetch', (event) => {
  event.respondWith((async () => {
    const parts = [
      new Response('<html><body>'),
      fetch('/dynamic-content'),
      new Response('</body></html>')
    ];
    return concatenateToResponse(parts);
  })());
});

Other packages similar to workbox-streams

Readme

Source

This module's documentation can be found at https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-streams

Keywords

FAQs

Last updated on 31 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc