Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

workbox-streams

Package Overview
Dependencies
Maintainers
6
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 6.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
decreased by-61.74%
Maintainers
6
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 23 Feb 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc