最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - Prevent UIWebView to cache JavaScript files? - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Jan 12, 2012 at 10:50 user920041user920041
Add a ment  | 

2 Answers 2

Reset to default 4

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.

I suspected UIWebView caching as well. Initially. But the actual problem was with Xcode treating .js files as pilable 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 piler think about the .js file, it does not detect the change and replace it when changed. Moving my .js file from pile phase to copy resources phase fixed the problem nicely.

发布评论

评论列表(0)

  1. 暂无评论