Reputation: 19262
by default the html5 cache works in the way that file/page/js/css/image, which mentioned in manifest, is cached when it loaded first, but i required that all files should be cached at once from my home page....
Upvotes: 1
Views: 273
Reputation: 19262
I got the script to cache all files at once which you mentioned in your manifest file.
<!DOCTYPE html>
<html manifest='../cache.manifest'>// reference path of your manifest file
<head>
<title>Untitled Document</title>
<script type="text/javascript">
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';
var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
cache.addEventListener('checking', logEvent, false);
cache.addEventListener('downloading', logEvent, false);
cache.addEventListener('error', logEvent, false);
cache.addEventListener('noupdate', logEvent, false);
cache.addEventListener('obsolete', logEvent, false);
cache.addEventListener('progress', logEvent, false);
cache.addEventListener('updateready', logEvent, false);
function logEvent(e) {
var online, status, type, message;
online = (navigator.onLine) ? 'yes' : 'no';
status = cacheStatusValues[cache.status];
type = e.type;
message = 'online: ' + online;
message += ', event: ' + type;
message += ', status: ' + status;
if (type == 'error' && navigator.onLine) {
message += ' (prolly a syntax error in manifest)';
}
alert(message);
document.getElementById("lblEvents").value = message;
}
window.applicationCache.addEventListener(
'updateready',
function () {
window.applicationCache.swapCache();
window.location.reload();
},
false
);
// end Script
</script>
</head>
<body>
<!--
Your body tags
-->
</body>
</html>
Upvotes: 0
Reputation: 75717
Appcache updates are atomic. Until all the files referenced in the manifest are downloaded the appcache is not used to serve them. If you need to load everything up, put everything in your manifest. Use a script to generate the manifest file instead of using wildcards.
Upvotes: 1