Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOM exception error 11 on swapCache()

I am playing with an application cache and having problems with the swapCache function.

I have created the world's simplest cache manifest file:

CACHE MANIFEST
# Timestamp: 2013-03-01 11:28:49

CACHE:
media/myImage.png

NETWORK:
*

Running the application for the 1st time gives me this in the console:

Creating Application Cache with manifest http://blah_blah/offline.appcache
Application Cache Checking event
Application Cache Downloading event
Application Cache Progress event (0 of 1) http://blah_blah/media/myImage.png
Application Cache Progress event (1 of 1)
Application Cache Cached event

All well so far. Then I swap out the image and change the timestamp in the manifest file and get the following:

Adding master entry to Application Cache with manifest http://blah_blah/offline.appcache
Application Cache Downloading event
Application Cache Progress event (0 of 2) http://blah_blah/media/myImage.png
Application Cache Progress event (1 of 2) http://blah_blah/Widget/?invoke=myWidgetFunctionName
Application Cache Progress event (2 of 2)
Application Cache UpdateReady event

At which point the applicationCache.swapCache() function is called giving me a DOM exception 11 error.

MIME types all correctly configured on the webserver.

Anyone got any ideas / can point me in the right direction? (I have read all the commonly linked appcache stuff online and can't see what am I doing wrong)

Thanks!

EDIT:

As I mentioned in the comments below, setting the expires headers on my web server for *.appcache files to expire immediately seems to have it working although I am still getting the DOM exception error(!?). I found the following blog entry which may help: Possible Fix for Offline App Cache INVALIDSTATEERR

...but I have no idea how to set the MIME types client side. My google-Fu skillz have deserted me. Anyone?

like image 915
Simple Simon Avatar asked Mar 01 '13 10:03

Simple Simon


1 Answers

I had the same issue. For a while I just disabled the cache if the browser was not chrome, but then I decided to try again, setting the mime-type as suggested. Firefox no longer throws an exception when I call swapCache(), and the whole refreshing process now works as expected. The mime-type has to be set server-side since the request isn't initiated from your web page, but the browser, so you have no control over how it reads the response. You have a couple options here. If you are using apache or IIS, you can do as koko suggested. If you are using a framework that handles routing for you and you configure the mapping of URLs to responses, such as rails or a python wsgi server, then you can typically set the content type manually. Here is my snippet of what I am using in my Python app using Bottle.py (WSGI based):

# BEFORE
@bottle.route(r"/<path:re:.+\.(manifest|appcache)>", auth=False)
def serve_cache_manifest(path):
    return bottle.static_file(path, SITE_DIR)

# AFTER
@bottle.route(r"/<path:re:.+\.(manifest|appcache)>", auth=False)
def serve_cache_manifest(path):
    return bottle.static_file(path, SITE_DIR, mimetype='text/cache-manifest')

Bottle comes with a utility function that handles returning static files that I am using. It has an optional parameter to set the mime-type.

tl;dr If you can't add the mime-type to your server configuration, you can almost always set it in your server side code (if you have any).

like image 176
casey Avatar answered Nov 02 '22 03:11

casey