2

I have a WebView that loads HTML files from within the private data of my app. I load those files from a server, then saves them to the private data folder. They come with JavaScript files, and CSS files, images, etc. So my WebView then display those HTML files just fine.

My problem is when I modify the content of those files on my server, and then download those files again in the app (first I made sure all files were deleted from the private data folder) and open the WebView, everything is updated except for the CSS files, the style remains the same. The quickest solution that I found to force the CSS files to be updated in the WebView is to delete all content for the app (in the settings) and then download the files again.

Note: I don't want to clear all data like history or whatever since I am using local storage on the WebView, but clearing resources is fine, if possible.

2 Answers 2

5

Add a timestamp or unique value to the end of the css filename when calling it if possible. I use this method within my webapp although i append the timestamp using php, im sure it can be done in html with JS also using event.timeStamp.

e.g

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0-alpha.2/jquery.mobile-1.4.0-alpha.2.min.css?timestamp=<? echo $timestamp?>"> 

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

I used the following code with myWebView to force re-load my css files:

myWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 

WebSettings.LOAD_NO_CACHE forces your html files to be loaded from the network. Doc: "Don't use the cache, load from the network. Use with setCacheMode(int)."

1 Comment

Works perfect. Loads CSS immediately.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.