npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

appcache-serviceworker-generator

v1.0.1

Published

Can generate an appcache manifest and ServiceWorker from same abstraction.

Downloads

7

Readme

appcache-serviceworker-generator

Can generates an appcache manifest and ServiceWorker from same abstraction.

While this largely ignores all the other cool stuff you can with ServiceWorker, I still found it useful for a small, static, offline app I'm building.

var createManifest = require('appcache-serviceworker-generator')
var fs = require('fs')

// give it a version (important for appcache)
var manifest = createManifest({version: '123'})

manifest.cache('/some/image.png')
manifest.cache('/')
manifest.fallback('/somepath.html /somefallback.html')

console.log(manifest.toAppCache())
// creates this string =>
// CACHE MANIFEST
// # version: 123
// 
// CACHE:
// /
// /some/image.png
// 
// NETWORK:
// *
// 
// FALLBACK:
// /somepath.html /somefallback.html
// 

// It can then also generate a *roughly* equivalent ServiceWorker as a string
// (it's your job to write to disk or whatever)
console.log(manifest.toServiceWorker())

How ready for primetime is this? Short answer: ¯\_(ツ)_/¯

I'm mainly sharing this because I think it's interesting, not because I think you should use it or saying that I'm interested in maintaining this long term.

I am using this on a small project where I've generated a static site with webpack and use the assets information that webpack has to generate an appcache for iOS (since no SW support) and a ServiceWorker for platforms that support it. It has a few very basic tests. Biggest question is how good the generated SW implementation actually is, feedback? Ping me on twitter: @HenrikJoreteg.

The app the initiates either selectively by first checking for support like this:

var cacheNanny = require('appcache-nanny')

if ('serviceWorker' in navigator) {
    navigator.serviceWorker
        .register('/sw.js')
        .then(function(registration) {
            // Registration was successful
            console.log('ServiceWorker registration successful with scope: ',    registration.scope);
        }).catch(function(err) {
            // registration failed :(
            console.log('ServiceWorker registration failed: ', err);
        })
} else {
	// this uses cache-nanny to actually give you a choice 
	// of when to init your appcache :)
	// see link below
    cacheNanny.start()
}

If you're planning on using appcache at all, I'd suggest checking out gr2m/appcache-nanny as used by the Hood.ie folks (who know a thing or two about offline).

example

See example directory. Run node example/run-me to re-generate the appcache and SW files in that dir.

install

npm install appcache-serviceworker-generator

credits

If you like this follow @HenrikJoreteg on twitter.

license

MIT