Prevent JavaScript caching in UIWebView?

I have a UIWebView that loads html, css and javascript.

When I ever make changes to the html or css that apply, I open the WebView again. But my Java scripts seem to be cached, changes to them are not returned when the WebView is reopened.

What am I missing here?

+4
source share
2 answers

This answer helped me: Prevent caching of .css files in UIWebView loaded from disk

Basically, you just need to add the increment as a parameter to the link, for example ?version=1 or ?time=12345678 . For example: <script src="myscript.js?version=123></script>

For dynamically loaded javascript, I use:

 script.src = "myscript.js?version="+new Date().getTime(); 

and the script is updated properly, without the version parameter, the file is cached in UIWebView.

+4
source

I suspected UIWebView caching. Originally. But the actual problem was that Xcode processed the .js files as compiled sources - Xcode puts them in the “Compilation Sources” build phase (project goal → “Phase Build” tab), while they should be in the “Copy package resources” phase . Regardless of whether the compiler thinks about the .js file, it does not detect changes and does not replace them when they change. Transferring my .js file from the compilation phase to copy resources fixes the problem.

+1
source

Source: https://habr.com/ru/post/1390616/


All Articles