应用程序缓存清单-内容在服务器上更新,但客户端不显示更新的内容
Application cache manifest - Content gets updated on server but client does not show updated content
首先,我很抱歉我的英语,我不擅长英语。
- 如果服务器更新了页面(html)的内容,那么我点击f5按钮在客户端重新加载此页,此页将显示更新后的内容。怎么做呢?
- 我有一个json文件,这个页面有一个按钮。当我点击按钮时,json文件的内容将显示。如果我编辑了这个json文件,那么我重新加载页面并单击此按钮,将显示编辑后的json文件。怎么做呢? 当我在服务器上更改页面内容时,我使用了缓存清单在客户端重新加载页面,客户端内容没有改变。
我在firefox30上执行它,失败了。但是在Google chrome上很好用。
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>
. 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" }
当服务器上使用缓存的东西(html, image, css, javascript)改变时,你只需要修改请求url来强制它重新加载。例如:
源url为:http://www.some.com/test.html
在修改test.html内容之后,
客户端浏览器中的HTML肯定会完全重新加载。您可以在firebug中查看更改。
相关文章:
- 从客户端更新Meteor.users
- 当客户端将两个按钮的javascript函数参数修改为相同时,SQL/PHP会更新多行
- 这是否可能延迟客户端的UpdatePanel更新
- 如何在客户端的元窗口小部件(JavaScript)中获取和显示更新的域模型
- Javascript:我无法获得一个文本框来显示客户端更新的值
- RxJS:在每次返回并行http请求时更新客户端
- 使用 Javascript 更新客户端中的事件
- 在 Rails 中,如何强制更新客户端的 js/css 文件
- 断开连接时更新客户端中的用户列表
- 节点,socket.io - 将新条目添加到新闻源时更新客户端
- 更新客户端上的Dojo存储数据
- 使用AJAX调用更新客户端时出现Javascript错误
- 如何使用xPages强制更新客户端的设计更改
- 在服务器发送新映像的间隔后更新客户端映像
- 实时web更新客户端到客户端
- 重新绘制/更新客户端数据的Meteor.js事件
- ASP.使用JQuery更新客户端双列表框,以及如何在服务器端检索结果
- Php /使用ajax自动更新客户端
- 从Node.js更新客户端DOM
- 如何跟踪服务器端更新客户端