Search code examples
iosiphoneuiwebviewuiwebviewdelegate

UIWebView first request too slow


I am using UIWebView to render web content in my application. I observed that the initial request when the app launches i.e. loadRequest, takes a long time to render the contents. However the subsequent requests which I don't track of, are much faster.
To confirm this, I created a standalone application which just has a UIWebView. This is the single line of code which I have added :

[wkBrowser loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.yahoo.com"]]];

The result is same. It takes around 15-20 seconds to load the page. However on tapping any link on web page, it takes 3-5 seconds to load the next page. I did put the UIWebView delegate function didFailLoadWithError, but there is never an error.
Question:

  1. Why is the first web request so slow ?
  2. How may I make it faster other than caching ?

Solution

  • The main reason is because, when you invoke the first time URL request, the server on the receiving end tries to display the information as per the requested device browser, ( like mobile, desktop). This is where you see a bit of delay.

    • The server take some time to resolve the request origin browse type & respond according to the browser type. This value is internally send from the browser. There is a difference in mobile safari & desktop safari.
    • The Server upon receiving the request, responds you back with the device type compatible page, ( mostly all domain servers are implementing this internally, the responsive pages).
    • If you want a "no delay situation", try calling the exact mobile version of the portal in concern.
    • The sub-sequent requests are treated from a known type browser, hence reducing the delay in response.

    Hope this solves the doubt.