Application Caching on iPad will not cache website

2019-04-02 02:06发布

I am running a DHTML page and want to cache the HTML, PHP file and IMAGE files that are referenced.

I have all the following files in WWW.sitename.COM/sub-dir/

.htaccess

AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType text/cache-manifest .manifest
AddHandler server-parsed .html
AddHandler application/x-httpd-php .html .htm 

cache.manifest

CACHE MANIFEST

# Cache manifest version 0.0.00002

NETWORK:

CACHE:

http://WWW.sitename.COM/sub-dir/index.html
http://WWW.sitename.COM/sub-dir/this.php
http://WWW.sitename.COM/sub-dir/images/first.png
http://WWW.sitename.COM/sub-dir/images/second.png

FALLBACK:

HTML manifest reference in THIS.PHP file...

<html manifest="http://WWW.sitename.COM/sub-dir/cache.manifest">

script to detect cache activity

<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+= ' (probably a syntax error in cache.manifest)';
}
console.log(message);
}



window.applicationCache.addEventListener(
'updateready',
function(){
    window.applicationCache.swapCache();
    console.log('swap cache has been called');
},
false
);

setInterval(function(){cache.update()}, 10000);

</script>

The console reports that nothing is being cached.

Any and all assistance gratefully received.

Thank you.

1条回答
做自己的国王
2楼-- · 2019-04-02 02:37

After much research the answer is...

  1. DO NOT include the names of the pages that hold the

    html manifest="cache.manifest"

    tag in the cache.manifest file.

  2. Ensure the cache.manifest file only uses relative URLs not ABSOLUTE.

  3. Ensure your iPad had been rebooted AT LEAST once after any system software update.

  4. The correct MIME type for the manifest file in the .htaccess file is

    AddType text/cache-manifest .manifest

Thanks to Bjorn at dev.bjorn.com/723 for helping me get there... a good blog post worth reading.

查看更多
登录 后发表回答