Giter Club home page Giter Club logo

sw-appcache-behavior's Introduction

About

A pair of modules meant to ease the transition off of AppCache and on to service workers.

Note: These libraries attempt to replicate the caching and serving behavior that AppCache offers, but does not include direct equivalents to the window.applicationCache interface, nor the related events that AppCache would fire in the window context.

Installation

There are two modules to install: one that is used from within the window context in your web app, and the other that's used in the context of your service worker.

npm install --save-dev appcache-polyfill-window
npm install --save-dev appcache-polyfill-sw

As an alternative to local installation & serving, you can load both libraries from a NPM CDN, like https://unpkg.com/ or https://www.pika.dev/.

Usage

Window client

<script type="module">
  import {init} from '/path/to/appcache-polyfill-window/build/index.modern.js';

  // Optional: define a callback that runs whenever caches are updated.
  // This is *rough* replacement for listening for AppCache updates.
  function myCachePopulatedCallback(urls) {
    // urls is an array of updated URLs
    // Your logic goes here.
  }

  init({
    cachePopulatedCallback: myCachePopulatedCallback,
  }).then(() => navigator.serviceWorker.register('sw.js'));
</script>

Service worker client

importScripts('/path/to/appcache-polyfill-sw/build/index.umd.js');

self.addEventListener('fetch', (event) => {
  // Alternatively, examine event.request and only use the
  // appcachePolyfill.handle() logic for a subset of requests.
  event.respondWith(appcachePolyfill.handle(event));
});

Feedback

Please open an issue with feedback or bug reports if you run in to problems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.