html 5 appcache用户控制的更新 [英] html 5 appcache user controlled updating

查看:51
本文介绍了html 5 appcache用户控制的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个ipad网络应用程序,该应用程序每月都会收到更改.但是我不知道如何让用户决定是否更新缓存.当发现清单文件发生更改时,ipad往往会继续进行更新.我想避免这种情况,以便尚未阅读本月刊的用户可以在需要时进行更新.我一直在寻找该问题的解决方案,但找不到任何可用的信息.

I'm working on an ipad webapp that will receive monthly changes. However I can not figure out how to let the user decide weither to update the cache or not. The ipad tends to just go ahead and update when it notices a change to the manifest file. I would like to prevent this so users that haven't finished reading this months issue can update when they feel like it. I've searched for a solution to this question but I fail to find any usable information.

设置我的应用程序的方式是,我有一个内容页面,该页面从数据库中获取数据,而所有其他文件(来自添加到内容页面的媒体的appart)都是静态的.

The way my app is set up is I've got a content page that fetches data from the database and all the other files (appart from media that is added to the content page) is static.

我有一个cache.manifest,其中包含每个文件,并且版本号在更新时在注释的顶部自动更改.

I have an cache.manifest with every file in it and a version number automatically changed on update at that top in a comment.

因此,对内容的更新意味着一个新的清单,这意味着将触发updateReady事件.如果有人可以为我提供任何指示,以指示如何捕获此错误并阻止其自动切换到新版本,那就太好了.

So an update to the content means a new manifest and that means the updateReady event is fired. If anyone could give me any pointers on how to catch this and prevent it from automatically switching to the new version, that would be nice.

谢谢!

推荐答案

如何阻止应用程序更新?

一旦应用程序脱机,它将保持缓存状态,直到发生以下情况之一:

Once an application is offline it remains cached until one of the following happens:

  • 用户清除了您网站的浏览器数据存储.
  • 清单文件已修改.注意:更新清单中列出的文件并不意味着浏览器将重新缓存该资源.清单文件本身必须是备用的.
  • 应用缓存已通过编程方式更新.

http://www.html5rocks.com/tutorials/appcache/beginner/#toc-updating-cache

简而言之:请勿修改清单文件.

In short: do not modify manifest file.

如何分别为每个用户更新清单文件?

如果用户第一次访问网站,则其浏览器会加载当前清单,因此我们将使用动态URL并动态生成清单文件:

If user visit website first time, his browser loads current manifest, so We'd use dynamic URL and generate manifest file dynamically:

<html manifest="manifest.php?version=2">

浏览器会记住URL manifest.php?version = 2 ,并且每次生成的清单文件保持不变,因此浏览器将不会更新(清单文件未修改).脚本文件如下所示:

Browser remembers URL manifest.php?version=2 and every time generated manifest file remains same, so browser won't update (manifest file is unmodified). Script file would looks like:

<?php

    header ( "Content-Type: text/cache-manifest" ) ;

    echo "CACHE MANIFEST\n\n" ;

    echo "# version " . $_GET [ "version" ] . "\n" ;

    echo "index.php\n" ;
    echo "styles.css\n" ;
    echo "scripts.js\n" ;

?>      

现在,如何强制浏览器从另一个URL加载清单,例如 manifest.php?version = 5 ?

Now, how to force browser to load manifest form another URL, for example manifest.php?version=5?

我试图更改清单属性的内容并调用 window.applicationCache.update()但是浏览器会从旧网址请求清单文件.

I tried to change manifest attribute content and call window.applicationCache.update() but browser requests manifest file from old URL.

另一种方式可能是:

  • 询问用户是否要更新;
  • 如果是,则保存cookie("wish_to_update = 1");
  • manifest.php中的cookie读取并检查用户是否希望更新;

在manifest.php中:

in manifest.php:

if ( $_COOKIE [ "wish_to_update" ] == "1" )
{
    // generate modified version
    echo "# version another than in your URL" ;
    setcookie ( "wish_to_update", "0" ) ;
 }
 else
 {
    // generate unmodified version
    echo "# version " . $_GET [ "version" ] . "\n" ;
 }

  • 修改后的清单文件将强制浏览器再次下载所有资源.
  • 这篇关于html 5 appcache用户控制的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆