Does the WebView in Flutter Cache Web Pages?
Yes, the WebView in Flutter can cache web pages, depending on the specific WebView implementation you are using. Here's a summary of the caching capabilities of different WebView plugins in Flutter:
flutter_inappwebview (former flutter_inappbrowser)This plugin provides a cacheEnabled
parameter with a default value of true
. Setting cacheEnabled
to true
enables browser caching for the WebView.
This plugin has an appCacheEnabled
parameter that you can set to true
to enable caching. Here's an example of how to use it:
WebviewScaffold(
key: _scaffoldKey,
url: widget.url,
clearCache: true,
appCacheEnabled: true,
);
webview_flutter official version
This plugin does not provide a specific parameter for controlling caching. However, you can check the Android source code to see how caching is handled.
By default, the caching behavior of the WebView depends on the underlying platform-specific implementation (iOS WKWebView
and Android WebView
).
The default cache mode for Android WebView is LOAD_DEFAULT
, which means that cached resources will be used when available and not expired. Otherwise, resources will be loaded from the network.
The default cache mode for iOS WKWebView
is also to use cached resources when available and not expired. Additionally, WKWebView uses a disk cache to store frequently visited pages for offline access.
To summarize, the WebView in Flutter can cache web pages, but the specific caching behavior depends on the WebView plugin you are using and the platform-specific implementation.