在使用webview
的时候发现,app在第一次启动带有webview的fragment的时候响应很慢,而后续再次开启却不是同样慢
05-05 20:57:18.721 I/WebViewFactory: Loading com.google.android.webview version 51.0.2704.81 (code 270408150)
05-05 20:57:18.897 W/System: ClassLoader referenced unknown path: /system/app/WebViewGoogle/lib/arm64
05-05 20:57:18.919 I/cr_LibraryLoader: Time to load native libraries: 14 ms (timestamps 7291-7305)
05-05 20:57:18.919 I/cr_LibraryLoader: Expected native library version number "51.0.2704.81", actual native library version number "51.0.2704.81"
05-05 20:57:18.939 V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {20922c4}
05-05 20:57:18.940 I/cr_LibraryLoader: Expected native library version number "51.0.2704.81", actual native library version number "51.0.2704.81"
05-05 20:57:18.941 I/chromium: [INFO:library_loader_hooks.cc(143)] Chromium logging enabled: level = 0, default verbosity = 0
05-05 20:57:19.015 I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
05-05 20:57:19.153 E/ActivityThread: Failed to find provider info for com.google.settings
05-05 20:57:19.197 D/cr_Ime: [InputMethodManagerWrapper.java:30] Constructor
05-05 20:57:19.210 W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring
05-05 20:57:19.211 D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: false
05-05 20:57:19.217 D/EgretLoader: EgretLoader(Context context)
05-05 20:57:19.224 D/EgretLoader: The context is not activity
查看logcat
发现只有第一次加载的时候会执行上方这些操作,有什么办法可以提高第一次打开webview的响应速度吗?
webview也是一个浏览器,需要下载文件,后面有了缓存自然变快。
优化不外乎按需加载,压缩之类的。基本浏览器可以用的优化,这里也用上就好了。
可以预开启webview并设置1像素的高和宽,并且预加载很多静态资源,国内有不少app就是这样做的,用户体验非常好。