WKWebView: Is it possible to preload multiple URLs

2020-03-28 04:07发布

Just migrated an app over to WKWebView and was wondering if there is any possible way to 'preload' multiple URLs, but only display one at a time?

I have a list of 5 URLs. I already know that I will be shown at some point in time, and I want to speed up the experience by pre-loading these for use in a single WKWebView.

3条回答
冷血范
2楼-- · 2020-03-28 04:25

I ended up just using NSURLCache and preloading all URLs using NSURLRequest and NSURLConnection. Then whenever I load a url into WKWebView it uses the cached requests per my cache policy.

查看更多
混吃等死
3楼-- · 2020-03-28 04:28

You can also preload five different WKWebView instances and swap them in/out when you need a specific URL. This depends on your UI and interaction of course.

查看更多
贼婆χ
4楼-- · 2020-03-28 04:33

A relatively straight-forward way to do this is to create five NSData objects (asynchronoulsly), each initialized using the known urls. When you need to display one of them, you can convert the NSData to a string, and then call WKWebView's loadHTMLString function to change the displayed page.

查看更多
登录 后发表回答