Reputation: 544
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.)
Upvotes: 3
Views: 4765
Reputation: 93
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 recommend 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!
Upvotes: 0
Reputation: 24815
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 overcome 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()
Upvotes: 0
Reputation: 89200
To 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 complete 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.
Upvotes: 6