Socket
Socket
Sign inDemoInstall

workbox-range-requests

Package Overview
Dependencies
Maintainers
4
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-range-requests

This library creates a new Response, given a source Response and a Range header value.


Version published
Weekly downloads
4.1M
increased by5.47%
Maintainers
4
Weekly downloads
 
Created

What is workbox-range-requests?

The workbox-range-requests npm package is a module that makes it easy to add support for efficiently handling partial content requests in service workers. It's part of the Workbox suite of tools, which are designed to make it easier to build offline-first Progressive Web Apps (PWAs). This package specifically deals with range requests, which are HTTP requests that include a Range header indicating which part of the content the client wants to receive. This is particularly useful for large files, like videos or audio, where the client might only need a portion of the file at a time.

What are workbox-range-requests's main functionalities?

Creating a range request handler

This code sample demonstrates how to create a route that handles .mp4 files using the RangeRequestsPlugin. When a range request is received for an MP4 file, the plugin will take care of slicing the appropriate chunk of the file and returning it to the client.

workbox.routing.registerRoute(
  /\.mp4$/,
  new workbox.rangeRequests.RangeRequestsPlugin()
);

Using RangeRequestsPlugin with a custom handler

This code sample shows how to use the RangeRequestsPlugin within a custom handler function. When a range request is received, the plugin's createPartialResponse method is used to generate the partial response from the cachedResponse.

workbox.routing.registerRoute(
  /\.mp4$/,
  async ({request, event}) => {
    // Assume `cachedResponse` will be the Response from the cache.
    const rangeRequestPlugin = new workbox.rangeRequests.RangeRequestsPlugin();
    return rangeRequestPlugin.createPartialResponse(request, cachedResponse);
  }
);

Other packages similar to workbox-range-requests

Keywords

FAQs

Package last updated on 09 Sep 2020

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