Reputation: 41
i create a html string with 500 p tag with timestamp in it
i use UIWebView
and WKWebView loadHTMLString:baseURL:
to load it,and wkWebView
is slower about 50% than UIWebVIew
. why?
UIWebView:0.1681529879570007
WKWebView:0.3913570046424866
Upvotes: 4
Views: 3910
Reputation: 983
To make WKWebView
faster, disabling WKWebView's data detectors worked for me. Swift version:
let webViewCofig = WKWebViewConfiguration()
webViewCofig.dataDetectorTypes = []
webView = WKWebView(frame: view.frame, configuration: webViewCofig)
To enable specific data detector, pass the specific type as .address,.link etc while setting dataDetectorTypes:
config.dataDetectorTypes = [.address]
Upvotes: -1
Reputation: 607
For me, creating static variable to avoid creating WKWebView multiple times worked. Objective-C example:
- (WKWebView *)webHeaderView
{
static WKWebView *_webHeaderView = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (!_webHeaderView)
{
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
_webHeaderView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
}
});
return _webHeaderView;
}
Upvotes: 1
Reputation: 7298
WKWebView is faster for displaying html from Strings. However, there is a bug that makes UIWebView faster by default, which is the phone number detection.
Running a viewController with the following code, webView
being respectively a UIWebView and WKWebView instance and keeping everything else identical I found WKWebView to take up to 2 seconds to load, while UIWebView loads almost instantly.
webView.loadHTMLString(HtmlStringInstance, baseURL: nil)
I'm by far not the only one to find this:
However, the solution is easy: Disable phone number detection for WKWebView and poof. There you go.
Upvotes: 1