I have one html file and one js file. The html file is refreshed, but the js file never gets reloaded. I have tried clearing the history and the cache as well as turning the iPad off. I have also deleted all nine pages in the iPad.
Finally I found a workaround. Renaming the js file solved the problem. But it is an awkward solution.
Is there a better way?
(I'm using the oldest iPad. Can't find out any version numbers.)
I have one html file and one js file. The html file is refreshed, but the js file never gets reloaded. I have tried clearing the history and the cache as well as turning the iPad off. I have also deleted all nine pages in the iPad.
Finally I found a workaround. Renaming the js file solved the problem. But it is an awkward solution.
Is there a better way?
(I'm using the oldest iPad. Can't find out any version numbers.)
Share Improve this question asked Oct 14, 2011 at 19:20 Kri-banKri-ban 5425 silver badges17 bronze badges 6- "Can't find out any version numbers." Why's that? – Lightness Races in Orbit Commented Oct 14, 2011 at 19:20
- 2 some more details there: stackoverflow./questions/32414/… – Amr Elgarhy Commented Oct 14, 2011 at 19:26
- @Tomalak: Maybe you can tell me where I can find them? e.g. Safari version. – Kri-ban Commented Oct 14, 2011 at 22:26
- When using Chrome on my laptop, the latest version of the js file is loaded from the server at FatCow. Also using Opera on the iPad works. The problem is, using Safari on the iPad does not load the latest js file. I think the problem is within Safari on the iPad. They are trying to save some bandwidth. – Kri-ban Commented Oct 14, 2011 at 22:29
- 1 The browser should issue a conditional get request to check if there is a newer version of the file, however the browser may choose to implement a more agressive caching strategy to make things faster. – Richard Garside Commented Oct 14, 2011 at 22:54
3 Answers
Reset to default 6To force a reload of a JavaScript file during development I typically add a query string parameter to the end of the file. Like this:
<script type="text/javascript" src="file.js?v=0.1"></script>
When development is plete for that version I include a version number in the file name.
This can be a good idea during testing even if you're not having problems with an iPad or similar. You want to be confident that people are seeing the latest version of the file and explaining how to empty their browser's cache or forcing them to refresh every page will cause problems and false bug reports.
This is a natural habit of caching. When the file actually changes, the iPad should reload the file. This is the same as a PC browser, or any other device with caching on.
To overe this, add a variable to the name of the javascript file, something like myfile.js?id=[ADD TIMESTAMP HERE]
On which you ofcourse add a timestamp with the programming language you use, for example in PHP: time()
I'm not 100% sure I understand your question, however if you are building a website and you don't want user's browsers to cache the javascript file I would remend adding a build number to the JS file each time you save it and update the html reference to the file +buildnumber.js.
Example:
instead of
<script src="myAwesomeJavscriptFile.js"></script>
make it:
<script src="myAwesomeJavscriptFile.001.js"></script>
Then the next time you change it make it:
<script src="myAwesomeJavscriptFile.002.js"></script>
The other way to do it is to send down specific no-cache headers for each file using your web server (Apache, Nginx, IIS)
Good luck!