Clear Webview Cache

If updates to your website aren't appearing in your native app built with Median, the issue is typically related to webview caching.

Median apps respect the same cache headers as modern browsers. This means your web server controls how long content is cached within the app. In most cases, updates will reflect after a few minutes or a page refresh. However, if you're still not seeing the latest changes, it’s likely due to aggressive cache headers or stale cached assets.

Implementation Guide

Website Configuration

To force the app to load the latest version of your assets (e.g., JavaScript or CSS files), you can use file versioning like:

application_782374982.js
styles_782374982.css

Updating the filename ensures the browser and app will request a fresh version from the server.

JavaScript Bridge Method

Median provides a JavaScript command to programmatically clear the webview cache. This is especially useful during development or when troubleshooting cache-related display issues.

↔️Median JavaScript Bridge

To clear the cache, open the URL:

median.webview.clearCache();

Android-Only

Some configuration options in appConfig.json apply specifically to Android apps. These settings allow you to control WebView behavior, including caching.

Automatically Clear Cache on Exit

Median includes a configuration option for Android apps to clear the WebView cache every time the app exits. To enable this, add the following in the appConfig.json:

"general": {
  "androidClearCache": true
}

Configure WebView Cache Mode

You can also control how the Android WebView handles caching by setting the cacheMode option. Add the following under the general section in your appConfig.json:

"general": {
  "cacheMode": "no_cache" // options: no_cache | cache_only | cache_else_network | default
}

Available values:

  • no_cache: Always load from the network, never use the cache.
  • cache_only: Only use cached content, never hit the network.
  • cache_else_network : Use cache if available, otherwise fetch from the network.
  • default: Use the system’s default caching behavior.