Socket
Socket
Sign inDemoInstall

appcache-autoupdate

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    appcache-autoupdate

Browser library for automated updates of offline first applications


Version published
Maintainers
1
Install size
1.91 MB
Created

Readme

Source

appCache AutoUpdate

Auto Updates for Offline First Applications

Installation

Install using bower for usage in browser:

bower install --save appcache-autoupdate

Usage

Make sure the manifest attribute is set on the <html> tag.

<html manifest="appcache.manifest">
<script src="appache-autoupdate.js">

AutoUpdate starts checking automatically for updates every 30 seconds. To prevent that, add data-autoupdate="false". You can also alter the check interval by setting a time in ms: data-autoupdate="10000".

The JS API:

// event API
AutoUpdate.on('updateready', reloadPage)

// AutoUpdate also offers reliable online/offline events
// in case the cache manifest could not be downloaded
AutoUpdate.on('offline', showOfflineIndicator)
AutoUpdate.on('online', hideOfflineIndicator)

// set interval for checking for updates in ms
// (default is 30000)
AutoUpdate.setInterval(60000)

// set alternative interval when offline
AutoUpdate.setOfflineInterval(30000)

// reload page when routing, if update is ready
function onRoute(event) {
  if (AutoUpdate.hasUpdate()) {
    location.reload(1)
  }
}

Use Case

I extracted appCache-autoupdate.js out of minutes.io, which is an Offline First web application, anno 2011. It's battle tested by a ton of users, devices, internet environment.

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 his 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

I don't have a demo app ready yet, I'm happily accepting pull requests though. But here's my idea for a tiny node.js app, hosted for free on Heroku or whereever:

  1. Autogenerate appcache.manifest that changes every 30s
  2. Autogenerate theme.css that changes the background color every time it gets requested
  3. Maka a tiny application with some tabs that the user can navigate between. Make sure the URL changes so the app can be reloaded & remain at the current tab.

Fine Print

appCache Autoupdate has been authored by Gregor Martynus, proud member of Team Hoodie. Support our work: gittip us.

License: MIT

Keywords

FAQs

Last updated on 10 Jun 2014

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc