UIWebView VS WKWebView to load local html

半城伤御伤魂 提交于 2019-12-29 09:08:12

问题


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

回答1:


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:

  • when I use wkwebview to load local html,I find it renders slower than uiwebview
  • UIWebView delay in loading local content
  • Slow loading UIWebView from string
  • Delay in loading a HTML string into a UIWebView
  • Why UIWebView work so slowly when loadHTMLString with UIWebView?

However, the solution is easy: Disable phone number detection for WKWebView and poof. There you go.




回答2:


WKWebView rendering performance is noticeable in WebGL games and something that runs complex JavaScript algorithms which UIWebView lacks.

You check the performance both in the Github.



来源:https://stackoverflow.com/questions/40499466/uiwebview-vs-wkwebview-to-load-local-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!