首先,我对我的英语感到抱歉,我不擅长英语。
我在firefox 30上执行它,它失败了。但它在谷歌浏览器上表现不错。
cache_test.html:
<!DOCTYPE html>
<html lang="ja" manifest="test.appache">
<!--<html lang="ja" manifest="test.manifest">-->
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<script src="jquery-2.1.1.min.js"></script>
<script src="test.js"></script>
<script>
$(function() {
updateAppCache();
});
</script>
<title>cache test</title>
</head>
<body>
Cache Test v15<br>
<button onClick="loadJSON('msg')">Load Json</button>
<div id="msg"></div>
<br>
<a href="test.html">test.html</a>
<!--<img src="1.jpg" >--> //content I want to edit, it will show at client
<!--<img src="2.jpg" >--> //content I want to edit, it will show at client
<img src="3.jpg" >
<img src="4.jpg" >
</body>
</html>
test.js:
function loadJSON(idMsg) {
jQuery.ajax({
url: 'test.json',
type: 'GET',
success: function(data, textStatus, xhr) {
$('#' + idMsg).text('success to load: ' + JSON.stringify(data));
},
error: function(xhr, textStatus, errorThrown) {
$('#' + idMsg).text('error to load: ' + textStatus);
}
});
}
function updateAppCache() {
// see: http://www.html5rocks.com/ja/tutorials/appcache/beginner/
console.log('updateAppCache - in');
var appCache = window.applicationCache;
// Update AppCache
appCache.update();
// After ready to update cache, call swap
appCache.addEventListener('updateready', function(e) {
// manifest changed
if (appCache.status === appCache.UPDATEREADY) {
appCache.swapCache();
console.info('Swap cache. AppCache status =' + appCache.status);
// reload page
window.location.reload(true);
} else {
console.warn('Do not swap cache. AppCache status =' + appCache.status);
}
}, false);
}
test.appcache:
CACHE MANIFEST
# 2014-07-13:v15
# AddType text/cache-manifest .appcache
# Explicitly cached 'master entries'.
CACHE:
cache_test.html
jquery-2.1.1.min.js
test.json
test.js
test.html
#1.jpg //content i want to save at the application cache at client.
#2.jpg //content i want to save at the application cache at client.
3.jpg
4.jpg
# Resources that require the user to be online.
NETWORK:
FALLBACK:
test.json:
{ "test":"What's up man!?", "foo":"---------" }
我要编辑的json文件的内容:
{ "test":"What's up man!?", "foo":"I will always love you" }
答案 0 :(得分:0)
当使用服务器上的缓存更改某些内容(html,image,css,javascript)时,您只需修改请求网址以强制重新加载。例如:
原始网址是:http://www.some.com/test.html
修改test.html内容后,
客户端浏览器中的html肯定会重新加载。你可以观察萤火虫的变化。