cheatsheets/js-appcache.md

33 lines
838 B
Markdown
Raw Permalink Normal View History

2014-04-01 07:59:39 +00:00
---
title: applicationCache
2015-11-24 04:48:01 +00:00
category: JavaScript
2014-04-01 07:59:39 +00:00
---
2017-08-29 22:28:48 +00:00
## Reference
{: .-one-column}
2014-04-01 07:59:39 +00:00
### applicationCache checking
2017-08-29 22:28:48 +00:00
```js
if (window.applicationCache) {
// "Naturally" reload when an update is available
var reload = false
2014-04-01 07:59:39 +00:00
2017-08-29 22:28:48 +00:00
window.applicationCache.addEventListener('updateready', () => {
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
window.applicationCache.swapCache()
reload = true
2014-04-01 07:59:39 +00:00
}
2017-08-29 22:28:48 +00:00
}, false)
2014-04-01 07:59:39 +00:00
2017-08-29 22:28:48 +00:00
setInterval(() => {
try {
// There's nothing to update for first-time load, browser freaks out :/
window.applicationCache.update()
} catch (e) { }
}, 1000 * 60 * 60) // Every hour
}
```
2014-04-01 07:59:39 +00:00
2017-08-29 22:28:48 +00:00
This is a deprecated HTML feature. See: [Using the application cache](https://developer.mozilla.org/en-US/docs/HTML/Using_the_application_cache) _(developer.mozilla.org)_