Reputation:
I have a UIWebView that loads html, css and javascript.
When ever I do a change in the html or css, that is applied ones I reopen the WebView. But my JavaScripts seems to be cached, changes in them dosen't get visbile when reopen the WebView.
What am I missing here?
Upvotes: 4
Views: 4505
Reputation: 31
I suspected UIWebView caching as well. Initially. But the actual problem was with Xcode treating .js files as compilable sources - Xcode puts them into a "Compile Sources" build phase (project targets -> Build Phases tab) whereas they should be in "Copy Bundle Resources" phase. Whatever compiler think about the .js file, it does not detect the change and replace it when changed. Moving my .js file from compile phase to copy resources phase fixed the problem nicely.
Upvotes: 1
Reputation: 9579
This answer helped me: Prevent caching of .css files in UIWebView loaded from disk
Basically, you just need to add an incrementer as parameter to the link like ?version=1
or ?time=12345678
. For example: <script src="myscript.js?version=123></script>
For a dynamically loaded javascript I'm using:
script.src = "myscript.js?version="+new Date().getTime();
and the script is updated properly, without the version parameter the file is cached in the UIWebView.
Upvotes: 4