Mark Corner
Mark Corner

Reputation: 131

How can I get iOS to cache HTML5 documents with query parameters?

I am attempting to open mobile safari from an iOS app to open an offline HTML5 app with openURL:

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/blargh.html"]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

blargh.html has an HTML5 manifest:

That manifest contains the html file: CACHE MANIFEST blargh.html

This all works as expected, when I open the URL from my iOS app, it is cached properly and works offline. However, it doesn't cache properly if I include dynamic cgi params:

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/blargh.html?q=p"]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

This basically means that I can't open an offline HTML5 app from an iOS app and pass it params and have it cache properly. I need to open the app in mobile safari and not a webview for reasons that are beyond this post. As far as I am aware there is no way to send post params through openURL. I would have hoped that mobile safari's caching system would have been smart enough to ignore cgi params.

Any suggestions?

Upvotes: 1

Views: 1237

Answers (1)

robertc
robertc

Reputation: 75747

Query params muck up the app cache because it's intended for static content. The usual approach is to load a static page and then use JavaScript to populate it dynamically, caching any data in DOM Storage so that you can use it offline too.

However, if you just need to cache the one file and your server supports routing or URL re-writing, then you can take advantage of the fact that the page that contains the link to the appcache file is always cached, so doesn't itself have to be listed in the manifest.

Re-write your URL from this:

http://localhost:8080/blargh.html?q=p

To:

http://localhost:8080/blargh.html/q/p

Upvotes: 1

Related Questions