开发者

html 5 appcache user controlled updating

开发者 https://www.devze.com 2023-03-09 18:51 出处:网络
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

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.

The way my app is set up is I've got a co开发者_运维问答ntent page that fetches data from the database and all the other files (appart from media that is added to the content page) is static.

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

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.

Thanks!


How to stop app to be updated?

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

  • The user clears their browser's data storage for your site.
  • The manifest file is modified. Note: updating a file listed in the manifest doesn't mean the browser will re-cache that resource. The manifest file itself must be alternated.
  • The app cache is programatically updated.

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

In short: do not modify manifest file.

How to update manifest file for each user individually?

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">

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" ;

?>      

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

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

Another way might be:

  • ask user if he/she wants to update;
  • if yes, then save cookie ("wish_to_update=1");
  • in manifest.php read cookie and check if user wishes to update;

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" ;
 }
  • modified manifest file will force browser to download all resources again.
0

精彩评论

暂无评论...
验证码 换一张
取 消