WkWebView delay time on Swift

When I'm trying to load a web page I'm using this part of code:
Code Block
let myURL = URL(string:"https://www.apple.com")
let myRequest = URLRequest(url: myURL!)
print(Date())/*Start time 11:47:28*/
self.myWV.load(myRequest)

I could see a delay from 1-3 seconds before to show the page even if I change the url.
Code Block
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print(Date())/*End time 11:47:30*/
}

That delay is normal?

I tried with both options:
  • Added a WKWebView in the Storyboard

  • Added a WKWebView programmatically.

Answered by OOPer in 649169022
On my Mac mini connected with 100Mbps ethernet cable to Giga-bps fiber-based global network.
Code Block
2020-11-24 23:00:01 +0000
2020-11-24 23:00:02 +0000


I haven't measured to sub-seconds, but I think it took more than one second.
1-3 seconds would not be a big delay, considering what happens behind WKWebView.

The value will change depending on many things, for example, DNS cache.
If you run your code on a well-trained actual device, it may be shorter.

That delay is normal?

Quite normal.

Accepted Answer
On my Mac mini connected with 100Mbps ethernet cable to Giga-bps fiber-based global network.
Code Block
2020-11-24 23:00:01 +0000
2020-11-24 23:00:02 +0000


I haven't measured to sub-seconds, but I think it took more than one second.
1-3 seconds would not be a big delay, considering what happens behind WKWebView.

The value will change depending on many things, for example, DNS cache.
If you run your code on a well-trained actual device, it may be shorter.

That delay is normal?

Quite normal.

Yes, I agree with it.

I also change the url with a custom backend that is fetching live data from the server and is 6 - 10 seconds before to show the web content into the web view.
Code Block
2020-11-25 09:10:11 +0000
2020-11-25 09:10:16 +0000
Code Block
2020-11-25 09:10:25 +0000
2020-11-25 09:10:31 +0000
Code Block
2020-11-25 09:10:56 +0000
2020-11-25 09:11:10 +0000

I tested on the simulator and also in different devices with LTE connection. Do you think the server could be the reason or the code or the internet connection?

Do you think the server could be the reason or the code or the internet connection? 

All of them possibly. But I will first check the network environment when the delay is far more than a few seconds.
WkWebView delay time on Swift
 
 
Q