1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-06-15 14:47:53 +02:00
cheatsheets/js-appcache.md
Rico Sta. Cruz f7c9650a56
Update
2017-08-30 06:28:48 +08:00

857 B

title category layout
applicationCache JavaScript 2017/sheet

Reference

{: .-one-column}

applicationCache checking

if (window.applicationCache) {
  // "Naturally" reload when an update is available
  var reload = false

  window.applicationCache.addEventListener('updateready', () => {
    if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
      window.applicationCache.swapCache()
      reload = true
    }
  }, false)

  setInterval(() => {
    try {
      // There's nothing to update for first-time load, browser freaks out :/
      window.applicationCache.update()
    } catch (e) { }
  }, 1000 * 60 * 60) // Every hour
}

This is a deprecated HTML feature. See: Using the application cache (developer.mozilla.org)