Determining a page is outdated on github pages
To have a better control of the caching of your website you can use the HTML5 cache manifest. See:
- A Beginner's Guide to Using the Application Cache on HTML5 Rocks
- Using the application cache on Mozilla Developer Network
- Cache manifest in HTML5 on Wikipedia
- Offline Web Applications W3C Working Group Note
- Offline Web applications at WHATWG
You can use the window.applicationCache.swapCache()
to update the cached version of your website without the need for manually reloading the page.
This is a code example from HTML5 Rocks explaining how to update users to the newest version of your site:
// Check if a new cache is available on page load.
window.addEventListener('load', function(e) {
window.applicationCache.addEventListener('updateready', function(e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
// Browser downloaded a new app cache.
// Swap it in and reload the page to get the new hotness.
window.applicationCache.swapCache();
if (confirm('A new version of this site is available. Load it?')) {
window.location.reload();
}
} else {
// Manifest didn't changed. Nothing new to server.
}
}, false);
}, false);
To avoid some confusion I'll add that GitHub sets the correct HTTP headers for cache.manifest files:
Content-Type: text/cache-manifest
Cache-Control: max-age=0
Expires: [CURRENT TIME]
so your browser knows that it's a cache manifest and that it should always be checked for new versions.