• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    JavaScript
  • Created almost 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Auto Updates for Offline First Applications

The appCache Nanny

Teaches the applicationCache douchebag some manners!

Build Status Dependency Status devDependency Status

As we all know, the Application Cache is a Douchebag. It's time to teach it some manners – The appCache Nanny for Rescue!

No more manifest attributes on your HTML files. Whether you want to cache your assets offline or not, when to start ... You Are In Controlβ„’

Have a glance:

// start to check for updates every 30s
appCacheNanny.start()

// optionally, pass intervals in ms
appCacheNanny.start({checkInterval: 10000})

// you can also check for updates at any time
appCacheNanny.update()

// The appCache nanny tells you if there is a new update available
appCacheNanny.hasUpdate()

// She tells you about all relevant applicationCache events
appCacheNanny.on('update', handleUpdate)
appCacheNanny.on('error', handleError)
appCacheNanny.on('obsolete', handleObsolete)
appCacheNanny.on('noupdate', handleNoupdate)
appCacheNanny.on('downloading', handleDownloading)
appCacheNanny.on('progress', handleProgress)
appCacheNanny.on('cached', handleCached)
appCacheNanny.on('updateready', handleUpdateready)

// plus some extra ones
appCacheNanny.on('init:downloading', handleInitDownloading)
appCacheNanny.on('init:progress', handleInitProgress)
appCacheNanny.on('init:cached', handleInitCached)
appCacheNanny.on('start', handleStart)
appCacheNanny.on('stop', handleStop)

// options
appCacheNanny.set('loaderPath', '/path/to/my-custom-loader.html')
appCacheNanny.set({ 'loaderPath': '/path/to/my-custom-loader.html' })
appCacheNanny.get('loaderPath')
appCacheNanny.get() // returns all options

Setup

  1. Copy appcache-loader.html into the root directory of your app, so that it's accessible at /appcache-loader.html.
  2. Create the manifest.appcache file and put it in the root directory of your app, next to /appcache-loader.html. If you use a different name, make sure to set it accordingly in appcache-loader.html.

Then load the appcache-nanny.js on your HTML pages.

<script src="appcache-nanny.js" async></script>

If you use bower, you can install it using:

bower install --save appcache-nanny

Or install via npm

npm install --save appcache-nanny

Background

I extracted appcache-nanny.js from minutes.io, which is an Offline First web application, anno 2011. It's battle tested by a ton of users, devices, internet environments.

minutes.io checks every 30 seconds if an update is available. And whenever the user navigates from one view to another, it reloads the page in case there is. As the assets are all cached, the user cannot tell that their page got just reloaded. It's silent, without any notification, or a prompt asking the user to reload the page. And it works very well so far.

Demo

appCacheNanny demo screencast

The appCache Nanny comes with a simple server for testing. Start it using Node:

npm start

It will start a local server at http://localhost:8888.

This is a static server with a few hidden features:

  • GET /bump-version increases the app version, so an update gets triggered on next check
  • GET /remove-manifest makes GET /manifest.appcache return 404, so it becomes obsolete on next check
  • GET /recreate-manifest undoes the previous step.

Gotchas

Unlisted paths get loaded from the server, not from cache (via FALLBACK)

Thanks to the iframe hack, your HTML pages do not get added to the list of cached assets locally, and won't get checked for updates each time. Which is great especially for a Single Page Application with pushState enabled. But if your app has paths like /welcome, /Dashboard, Meeting/123 and your manifest.appcache looks something like

CACHE MANIFEST

/
/app.js
/styles.css

FALLBACK:
/ /

Beware that opening http://yourapp.com will always show the currently cached version, as it is explicetly listed, while http://yourapp.com/welcome and other paths will load the page from the server, unless the user is offline.

You might have learned that assets that are not listed in the cache manifest cannot be loaded at all, even when online. But that's not the case if the loaded HTML page does not have the manifest property on the html tag.

Acknowledgement

The appCache Nanny is based on tremendeous amount of research others have done on applicationCache. I'd like to highlight

TODOs / IDEAs

  • on obsolete, remove the iframe, load it again to check if a new *.appcache path has been set. If yes, update and trigger updateready event, otherwise trigger obsolete event

Fine Print

The appCache Nanny has been authored by Gregor Martynus, proud member of the Hoodie Community.

License: MIT

More Repositories

1

twitter-together

🐦 A GitHub action to tweet from a repository
JavaScript
598
star
2

awesome-buttons

awesome buttons!
HTML
413
star
3

CORS-Proxy

ΓΌber-simple node.js-Proxy to enable CORS request for any website
JavaScript
380
star
4

merge-schedule-action

GitHub Action to merge pull requests on a scheduled day
TypeScript
138
star
5

cloudflare-worker-github-oauth-login

Use a Cloudflare worker for GitHub's OAuth login flow
HTML
109
star
6

octokit-plugin-create-pull-request

Octokit plugin to create a pull request with multiple file changes
TypeScript
91
star
7

javascript-plugin-architecture-with-typescript-definitions

Plugin architecture example with full TypeScript support
TypeScript
82
star
8

before-after-hook

wrap methods with before/after hooks
JavaScript
73
star
9

milestones

A GitHub backed Milestone thingy
JavaScript
70
star
10

create-or-update-pull-request-action

A GitHub Action to create or update a pull request based on local changes
JavaScript
67
star
11

editable-table

A web component for editing a collection of records
JavaScript
50
star
12

initials

extract initials from and add initials to names
JavaScript
44
star
13

moment-parseformat

A moment.js plugin to extract the format of a date/time string
JavaScript
44
star
14

github-project

JavaScript SDK for GitHub's new Projects
JavaScript
34
star
15

cloudflare-worker-github-app-example

A Cloudflare Worker + GitHub App Example
JavaScript
27
star
16

find-hearted-contributions

Find contributions that you bookmarked by adding a heart emoji
JavaScript
27
star
17

spawn-pouchdb-server

Configurable per-app pouchdb-server as a drop-in replacement for CouchDB
JavaScript
26
star
18

restaurant-graphql

A tasty introduction to GraphQL
JavaScript
25
star
19

pdf-editor

WYSIWYG PDF-Editor, plugin-free, using pdfkit and pdf.js
HTML
25
star
20

phantomjs-console

Control a headless browser console right from your terminal
CoffeeScript
25
star
21

localstorage-memory

localStorage-compatible API, but only stored in memory
JavaScript
22
star
22

to-id

Normalises strings for comparison or usage as IDs
JavaScript
21
star
23

helpdesk

Answering all your GitHub API/automation questions live on Twitch
JavaScript
20
star
24

navigable-table

A Bootstrap plugin for elegant navigating along table inputs
JavaScript
19
star
25

couchdb-view-tester

Your friendly helper to quickly iterate on CouchDB views
JavaScript
19
star
26

octokit-plugin-rename-branch

Octokit plugin to rename a branch in a github repository
TypeScript
18
star
27

glitch-github-app

Deploy Probot apps using a web-based setup form
HTML
18
star
28

universal-user-agent

Get a user agent string in both browser and node
JavaScript
17
star
29

release-notifier-action

GitHub Action to notify repositories about the repository's releases using a GitHub App
JavaScript
14
star
30

universal-github-app-jwt

Calculate GitHub App bearer tokens for Node & modern browsers
JavaScript
14
star
31

semantic-release-plugin-update-version-in-files

Turns GitHub REST API endpoints into generic request options
JavaScript
13
star
32

get-json-paths-action

A GitHub Action to access deep values of JSON strings
JavaScript
13
star
33

couchdb-user-management-app

Web app to manage CouchDB users and database security settings
JavaScript
12
star
34

contenteditable-autocomplete

Autocomplete for contenteditable tags
JavaScript
11
star
35

dream-pdf

A modular JavaScript library to create PDFs
JavaScript
11
star
36

octokit.rest

Sourcode for the octokit.rest website
JavaScript
11
star
37

wkhtmltopdf-node-heroku

Example node app for heroku, that converts any publicly available URL to a PDF
JavaScript
10
star
38

app-stats-action

JavaScript
10
star
39

humble-localstorage

wraps localStorage and adds .getObject(), .setObject(), .isPersistent
JavaScript
9
star
40

expandable-input

A Bootstrap plugin to use <{span|div|...} contenteditable> as auto-expanding inputs.
JavaScript
9
star
41

sandbox

@gr2m's little sandbox to play
JavaScript
9
star
42

browser-supports-log-styles

returns true if browser supports console log styling
JavaScript
9
star
43

nice-tables

some simple CSS magic for a basic treatment of tables
HTML
8
star
44

octokit-release-asset-upload

Upload files to a GitHub Release from Node and the browser
JavaScript
7
star
45

testmate

A humble cross node/browser/saucelabs test runner
JavaScript
7
star
46

open-purse

Transparently share revenue from GitHub sponsors and GitHub App marketplace subscriptions. Coming soon!
HTML
6
star
47

ideas

a place for my side project ideas. Come build them with me :)
6
star
48

octokit-oauth-app-now-example

Serverless OAuth API using @octokit/oauth-app & now
TypeScript
6
star
49

github-api-wishlist

A curated wishlist for GitHub's APIs.
6
star
50

github-openapi-graphql-query

Send GraphQL queries against GitHub's REST API specifications
JavaScript
6
star
51

merge-dependency-update-prs

Load Dependbapot PRs from your notifications, merge the green ones and remove notifications
JavaScript
5
star
52

write-csv-file-action

GitHub Action to append a row to a CSV file
JavaScript
5
star
53

semantic-release-github-npm-registry

semantic-release plugin to publish an npm package to GitHub’s npm registry
5
star
54

node-net-interceptor

Intercept outgoing network TCP/TLS connections
JavaScript
5
star
55

has-localstorage

returns true if localStorage is supported _and_ persistent
JavaScript
5
star
56

org-stats-action

A GitHub Action to track statistics for a GitHub organization in a CSV file
JavaScript
5
star
57

create-user-to-server-token

Static website to generate user-to-server tokens scoped to a GitHub App's installations and permissions
HTML
5
star
58

github-app-slack-demo

A minimal GitHub App that integrates with Slack
JavaScript
5
star
59

axios-upload-stream

JavaScript
5
star
60

github-actions-sentry-example

GitHub Action example that sends errors to Sentry
JavaScript
4
star
61

await-npm-package-version-action

GitHub Action to wait for an npm package version to become available
JavaScript
4
star
62

add-coc

Script for https://github.com/gr2m/mutate-github-repositories-cli to create a CODE_OF_CONDUCT.md file unless already present
JavaScript
4
star
63

universal-esm-packages-test

Universal ES Module test
JavaScript
4
star
64

github-organization-repository-auditing-action

A GitHub Action to audit repository access across an organization
JavaScript
4
star
65

octokit-oauth-app-begin-example

serverless example using begin.com
JavaScript
4
star
66

gr2m

it me!
4
star
67

node-http-recorder

Library agnostic in-process recording of http(s) requests and responses
JavaScript
4
star
68

couchdb-remove-conflicts

CLI tool to remove all conflicts from a CouchDB database
JavaScript
4
star
69

github-webhook-relay

Receive webhooks from a GitHub repository via WebSocket
JavaScript
4
star
70

cowsay-action

The cowsay GitHub Action written in JavaScript
JavaScript
3
star
71

my-AI-adventure

A work-in-progress Idea to generate stories where your own children are the main characters
3
star
72

octokit-rest-plugin-example

@octokit/rest plugin example
JavaScript
3
star
73

status.hood.ie

CSS
3
star
74

create-pull-request-comment-action-example

3
star
75

set-cron-schedule-action

Set the cron schedule for a GitHub Action
JavaScript
3
star
76

BaBoCoCo

BackboneConf Contacts!
3
star
77

octoherd-script-bump-node-version-in-workflows

Octoherd script to set the node-version input for actions/setup-node to the latest LTS major version
JavaScript
3
star
78

node-live-sync

watches for file changes and syncs via sftp (more options to be added)
JavaScript
3
star
79

node-http-interceptor

Intercept and mock outgoing http/https requests
JavaScript
3
star
80

bahncard-calculator

because FUUUU bahn.de
CoffeeScript
3
star
81

node-bin-example

minimalistic CLI tool example
JavaScript
3
star
82

uscis-service-center-processing-times

Get processing time for one or all USCIS service centers
JavaScript
3
star
83

octokit-webhooks.js-legacy

Node.js web handler / middleware for processing GitHub Webhooks
JavaScript
3
star
84

octokit-plugin-hello-world

Simple Octokit.js plugin for demo purposes
TypeScript
3
star
85

localstorage-tutorial

Build a simple HTML page that stores data in and renders data from localStorage
JavaScript
3
star
86

github-webhook-relay-cli

CLI to receive webhooks from a GitHub repository via WebSocket and forward them to your localhost server
JavaScript
2
star
87

github-openapi-graphql-server

GraphQL Server to query GitHub REST API specifications
JavaScript
2
star
88

pouchdb-attachments-sync-test

PouchDB Sync Test for attachments
HTML
2
star
89

update-authors-app

GitHub App that creates and updates the AUTHORS file in your repository each time a pull request is merged
JavaScript
2
star
90

octokit-rest-plugin-add-endpoints

@octokit/rest plugin to add endpoint methods based on a routes.json file
JavaScript
2
star
91

boop-gregors-nose-test

2
star
92

Mad-Libs-Forms

a how-to for mad lips styled form that are claimed to "Increase Conversion 25-40%"
HTML
2
star
93

watch-single-file-action-example

JavaScript
2
star
94

bootstrap.modalform.js

simple method to create dynamic forms embedded in bootstrap modals
JavaScript
2
star
95

mite.goal

A simple, HTML-based app to set and visualize goals for time or revenue tracked with mite (http://mite.yo.lk/)
JavaScript
2
star
96

selsa

Selenium, Saucelabs, Webdriver and lots of despair
JavaScript
2
star
97

octokit-plugin-get-semantic-releases

Get repository releases with semantic version tags (e.g. `v1.2.3`, `v2.0.0-beta.1`, etc)
TypeScript
2
star
98

riot-router-example

simple riot.js app with route-based content toggling
HTML
2
star
99

boop-gregors-nose

CLI to boop my nose
JavaScript
2
star
100

github-graphql-demo

An example GitHub dashboard implemented using REST & GraphQL for comparison
JavaScript
2
star