I am having a lot of trouble clearing the WebView cache in my UWP app.
If I edit the content of a JS file linked from my HTML page, I can't get the change into my app unless I re-install the app.
The static WebView.ClearTemporaryWebDataAsync() method doesn't seem to work.
I have also tried adding headers to the request to disable caching:
private void reloadPage()
{
string url = getUrl();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(url));
request.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
request.Headers.Add("Pragma", "no-cache");
myWebView.NavigateWithHttpRequestMessage(request);
}
I also tried the following, on a punt (I'm not sure if this affects the WebView's caching behaviour), but still no joy:
private void onWebviewLoaded(object sender, RoutedEventArgs e)
{
Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
myFilter.CacheControl.WriteBehavior = Windows.Web.Http.Filters.HttpCacheWriteBehavior.NoCache;
myFilter.CacheControl.ReadBehavior = Windows.Web.Http.Filters.HttpCacheReadBehavior.Default;
WebView.ClearTemporaryWebDataAsync().AsTask().Wait();
reloadPage();
}
Any help would be very much appreciated!
EDIT (14/12/15): I have found that adding headers to the request (as in the first code example above) does work, but only if this has been in place for the lifetime of the app, since install. Which makes sense, as it's just saying not to cache this particular request - it could still use an old cached version.
This works as a cludge for now, but it would be much nicer to be able to make use of caching (e.g. for the duration of an app session), then later clear the cache (e.g. on next startup).
EDIT (14/07/16): The above approach doesn't seem to bear out. Caching behaviour seems to be erratic in the webview...
On a clean install of the app, I can see changes to CSS/JS files with absolutely NO code to clear/disable cache. Then at some seemingly arbitrary point, files seem to be cached, and I cannot clear them from the cache.
I don't know if it helps but try to add a timestamp behind the url (url + "?=" + sometimestamphere)
I had a similar problem with css in an UWP app not getting cleared. I ran ProcessMon and found that the UWP app was caching .css and .js files in Windows 10 at: C:\Users\\AppData\Local\Packages\microsoft.windows.authhost.sso.p_8wekyb3d8bbwe\AC\INetCache\Q8IHZDMV. I'm using the Web Authentication Broker so the scenario might be slightly different. If a location similar to this doesn't pan-out, you might want to try to run processmon (part of the SysInternals suite) when you start-up your UWP app to see if you can identify the path the UWP app is using for caching these assets. Once there, deleting these assets and restarting the app did the trick.
This finally works for me:
Refreshing the webview seems to do a reload:
It's definitely a hack, but you may be able to insert at that some point in your application lifecycle to force reloading your content. Perhaps after the "mainWebView_NavigationCompleted()" event?