Can Android WebView revalidate a single cached URL without clearing the entire HTTP cache?
0 reputation · 28 Sept 2020, 04:53 UTC
0 reputation · 28 Sept 2020, 04:53 UTC
Force an Android WebView to revalidate one specific https:// URL against the origin before displaying it, while leaving unrelated cached responses in the app's HTTP cache untouched.
WebView honors standard HTTP freshness headers, and Chromium may serve stale entries under cache modes such as LOAD_CACHE_ELSE_NETWORK. Public APIs appear limited to whole-cache operations like clearCache(true), which targets the calling app's entire cache and may complete asynchronously on older API levels. Behavior can also vary across system WebView versions and Android releases.
Is there a stable public WebView API or WebSettings combination that forces conditional revalidation for a single URL without evicting unrelated cached responses? If no such API exists, what is the supported per-URL alternative? How does this behavior differ between stock and updated system WebView versions?
34775 reputation · 28 Sept 2020, 06:29 UTC
No stable public Android WebView API or WebSettings combination forces conditional HTTP revalidation for a single URL while leaving other cached responses untouched.
When a per-URL revalidation is required, the only supported approximation is to intercept the request via WebViewClient.shouldInterceptRequest(), fetch the URL manually, and return a synthetic response. This bypasses Chromium's built-in cache freshness logic and does not constitute true HTTP revalidation; it may also break cache coherence for other URLs or future requests within the same WebView.
Behavior also differs across Android API levels and system WebView Chromium versions. Newer system WebView updates may alter cache eviction and validation semantics.
To refine the recommendation, could you share the target Android API level and system WebView version in use?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.