Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 application manifest not clearing cache on manifest change

I have a rails app that I'm trying to get using HTML5 application caching using Rack::Offline. The application.manifest file is set up and is being downloaded and checked by my HTML page. The manifest looks as follows:

CACHE MANIFEST
# 2d9bf2b03a07dc960fd8fe69659ceeffd4d28ccf8619669a506c3682bf223878
404.html
422.html
500.html
login.html
stylesheets/scaffold.css
javascripts/jquery.min.js
javascripts/jquery.js
javascripts/application.js
javascripts/rmbz.js
javascripts/rails.js
images/rails.png

NETWORK:
/

The page I'm accessing is localhost:3000/mobile, and it has cached wonderfully (viewable when I take down the rails server). However, the application.manifest file that it references has changed (in fact it changes with each request by manipulating the commented hexadecimal id), but Chrome is not updating the page. The console log in Chrome gives the following:

Document was loaded from Application Cache with manifest http://localhost:3000/application.manifest
Application Cache Checking event
Application Cache Downloading event
Application Cache Progress event (0 of 12) http://localhost:3000/login.html
Application Cache Progress event (1 of 12) http://localhost:3000/404.html
Application Cache Progress event (2 of 12) http://localhost:3000/422.html
Application Cache Progress event (3 of 12) http://localhost:3000/javascripts/rails.js
Application Cache Progress event (4 of 12) http://localhost:3000/javascripts/rmbz.js
Application Cache Progress event (5 of 12) http://localhost:3000/images/rails.png
Application Cache Progress event (6 of 12) http://localhost:3000/500.html
Application Cache Progress event (7 of 12) http://localhost:3000/javascripts/jquery.js
Application Cache Progress event (8 of 12) http://localhost:3000/stylesheets/scaffold.css
Application Cache Progress event (9 of 12) http://localhost:3000/javascripts/jquery.min.js
Application Cache Progress event (10 of 12) http://localhost:3000/mobile
Application Cache Progress event (11 of 12) http://localhost:3000/javascripts/application.js
Application Cache Error event: Manifest changed during update, scheduling retry

I don't quite understand why it's failing. It seems to be doing everything it should until the last line! I get a similar log if I navigate in my browser to localhost:3000/application.manifest - it seems that the manifest is cached itself, so could that be why it complains that the manifest has changed? Any ideas?

Thanks!

like image 376
kmc Avatar asked Jan 18 '11 22:01

kmc


People also ask

What is the MIME type for HTML5 application cache manifest file?

A manifest file must be served with the mime-type text/cache-manifest .

Which of the following is not a valid section of Appcache manifest?

Which is not the section of manifest? Explanation: If the files are not in cache they come from a list of the files in the network. Cache is the default section.

Does the section cache do in a manifest file?

The CACHE section contains files you want to load and store on the user's machine. The first time the user loads your app, the browser will store all the files in the CACHE section of your app cache manifest. The NETWORK section contains all the resources that require a network connection to be loaded.

What is a manifest file in HTML5?

The manifest file is a simple text file that lists the resources the browser should cache for offline access. To learn more about how to create the manifest file, please read our HTML5 Application Cache chapter.


2 Answers

Rack::Offline seems to be using a time window for refreshing the hash in the manifest file (lib/rack/offline.rb:84).

now = Time.now.to_i - Time.now.to_i % @cache_interval

# @cache_interval defaults to 10 seconds 

The manifest file is requested twice by the browser: once at the beginning of the request and once all cache was successfully stored offline.

When handling your request takes considerable time (lots of assets have to be loaded) it can happen that the first request is answered in one time window and the final request is handled in another. As a consequence the hashes in both manifests will not match and you get the "Application Cache Error event: Manifest changed during update, scheduling retry" error as a result.

In order to diminish the odds of such an error during development you can choose to set a greater cache_interval as follows:

offline = Rack::Offline.configure :cache_interval => 20 do
    ...
end
like image 50
Samuel Avatar answered Nov 08 '22 07:11

Samuel


The last file requested by Chrome is application.manifest, if this has changed since the original request (as you say it has) then that invalidates the cache. You need to keep the manifest unchanged until one of the files listed in the manifest has changed.

like image 31
robertc Avatar answered Nov 08 '22 07:11

robertc