1

I'm in the process of developing an iPad web app that needs to be in Fullscreen mode and Airplane mode at the same time.

We've been using the Cache Manifest to store all the files we need but the tricky part is that right now we're passing information in the URL ie. file.html?account=234 and when you try to link to a file like this during Airplane mode an error is returned saying that the iPad can't access the domain... despite the fact that file.html is cached in the Cache Manifest.

It seems like the iPad thinks that file.html and file.html?account=234 are two completely different files/URLs, so then it sees that it's not in the Cache Manifest and tries to connect to the server.

The idea behind all of this is that we display a list of accounts in index.html from a JSON file and then in file.html (we get the account param with the jQuery $.url().param() plug-in) and build the account info from the JSON file.

It's like a lo-fi way of using the JSON file as a Database, and it works fine in Fullscreen Mode.. unless you're in Airplane Mode. And that's a problem because this prototype needs to work without internet connections.

It seems like my approach is completely wrong, but I'm sort of at a loss now. Is there a way to use AJAX to load the file.html into the index.html and at the same time pass along account=234?

matyus
  • 13
  • 5
  • In general, so far as the cache is concerned, file.html and file.html?param=val ARE different pages. – jasonbar Sep 15 '11 at 15:41

3 Answers3

1

file.html?account=234 and file.html are 2 different urls. You could add the account number in the hash(#) instead of as a parameter. But I think it would be nicer if you just stored the account number in a cookie or localstorage.

Gerben
  • 16,747
  • 6
  • 37
  • 56
  • Even if the file with the querystring was already visited, under normal circumstances trying to pull it again will still go back to the server anyway because it has a querystring. – Rex M Sep 15 '11 at 15:44
  • @rex http://stackoverflow.com/questions/850187/caching-from-urls-with-a-query-string – Gerben Sep 15 '11 at 15:50
0

Ok so I'm happy to report that localStorage was the perfect solution. I just stored a key/value as "account","234".

matyus
  • 13
  • 5
-1

Safari, like all browsers, will not cache URLs with a querystring. This fact is used all the time to force AJAX calls to be refreshed by adding a querystring.

At the simplest level, try switching to use component parts of the URL instead - like /account-234/.

Or as you said, your approach may simply not make sense. Have you looked at using HTML5 local storage? You can pull down all the relevant information into a data structure that makes sense for you and store it for offline usage.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Rex M
  • 142,167
  • 33
  • 283
  • 313
  • 1
    I'm not sure if that is correct. Old browsers didn't, but as far as I know all modern browsers do. Also your solution doesn't work with the manifest, unless you create a dynamic manifest for every user. – Gerben Sep 15 '11 at 15:44
  • @Gerben I think you are mistaken. There is no difference between using a component part of the URL or using a querystring as parameters. It's a common technique to use a querystring parameter to "trick" the browser into always going back to the server when making AJAX calls. – Rex M Sep 15 '11 at 15:45
  • But you still need to add the url to the manifest, with querystring or with path encoded account number. – Gerben Sep 15 '11 at 15:48
  • @Gerben exactly - when connected, pull /account-234. When offline, subsequent calls to that file will hit the cache. – Rex M Sep 15 '11 at 15:51
  • No. When it is not in the manifest, it will result in a error. Unless you add a network section in the manifest, but then you still get an error when in airplane mode. – Gerben Sep 15 '11 at 15:57