iPhone webapp caches js, won't refetch after some time?

487 Views Asked by At

I have a webapp that is designed a certain way, in index.html it has a script tag:

<script type="text/javascript" src="http://myserver.com/app.js" />

Inside that app.js, there's code like this (w/ jQuery):

function _run(data) {
  /* load data, modify dom, show content, page shows to user... */
}
$(function() {
  /* load jsonp that will call above function */
  $.getScript("http://myserver.com/data.js");
});

And inside that data.js, there's the jsonp stuff:

_run({foo:'bar'});

It's a bit of a weird setup I guess, but I need it to be like that for now. The point is it works on computer browsers. I am having problems with iPhone - if I make it a webapp (add it to homescreen). The first time it will load just fine, if I switch to homescreen and back to the webapp, it will refresh and load again just fine.

BUT, if I wait about half an hour or an hour, and go back to that webapp - it will not load content. I see the browser has "refreshing" icon spinning for a second as if it's refetching content, but then it stops. In other words it looks like that jsonp function is not executing - which in turn does not load the page. I don't see any errors in Safari console.

Am I missing something? Is there something special about iPhone browser? Is something cached in a weird way? :[

P.S: I know that $.getScript function adds timestamp to the end of the url every time (at least on computer browsers)

UPDATE:

Found an error happening saying it cannot find google variable (I am including google maps with a script tag, then declaring google var and using it). This is happening ONLY after about an hour of inactivity for me on webapp. And once I restart it a couple of times, the error disappears (only to happen again an hour later).

Fixed that with a callback (even though execution should've paused till script tag was downloaded). Now the same error with $ variable (jQuery).

There's obviously something wrong with script tags it seems. Broken only on mobile AND after about an hour. No idea what's up.

UPDATE 2:

So, basically to sum all of the above, I am under impression that <script> tags fail to download/run randomly after refreshing page half an hour or an hour later. This happens on my old iPhone 3G running iOS 5.0.1 (noticed doesn't really matter if it's webapp or iPhone safari). As of right now, I am doing a bunch of hacks to check and recheck whether random js is there... Total ugliness. Can some js/mobile guru help me understand what's going on?

0

There are 0 best solutions below