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

astrojs-service-worker

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astrojs-service-worker

An Astro integration to generate a Service Worker. Powered by Workbox.

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
increased by191.23%
Maintainers
1
Weekly downloads
 
Created
Source

Astro Service Worker

An Astro integration to generate a Service Worker. Powered by Workbox.

What is this? 🧐

A minimal wrapper around Workbox to quickly add a service worker to your Astro static site. Get precached pages and offline support out of the box.

Examples 🚀

Coming Soon!

Installation & Usage 📦

  1. Add this package to your project:
    • npm install astrojs-service-worker or yarn add astrojs-service-worker
  2. Add astrojs-service-worker to your astro.config.mjs integrations:
import { defineConfig } from "astro/config";
+ import serviceWorker from "astrojs-service-worker";

export default defineConfig({
+  integrations: [serviceWorker()],
});

API Overview 🛠

NameDescriptionType
registration.autoRegister

Autoregister the service worker.

If false, then the application must initialize the service worker by invoking register. Set this to false if you'd like to take control over when you service worker is initialized. You'll then need to add something like the following to your application:

if ("serviceWorker" in navigator) {
  navigator.serviceWorker.register("/service-worker.js");
}

Defaults to true. Recommended: true.

boolean | undefined
workbox Options passed to `worbox-build`. See all available configuration options [here](https://developer.chrome.com/docs/workbox/modules/workbox-build/)

Defaults to GenerateSW which will generate a service worker.

Note: injectManifest is not supported at this time. If you would like it to be supported, please open an issue

InjectManifestOptions | GenerateSWOptions

Common Service Worker Pitfalls ⚠️

You must serve your application over HTTPS in production environments. Service Workers must be served from the site's origin over HTTPS.

Some browsers special case localhost, so this is may not necessary during local development. HTTPS is not handled by this library.

The service worker origin constraint means that service workers can not control pages on a different subdomain. Eg mysite.com can not be controlled by a service worker if that was served from a subdomain such as mycdn.mysite.com.

Contributing 👫

PR's and issues welcomed! For more guidance check out CONTRIBUTING.md

Licensing 📃

See the project's MIT License.

FAQs

Package last updated on 31 Jul 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