Search code examples
iosuiwebviewwkwebview

UIWebView and WKWebView stall on broken resource link


I have a webview that loads html content with broken resource link(s) ( ie <img src = someBrokenLink> ) This webview will eventually load all the other contents, but it takes about 15 seconds or so.

I used the Web Inspector and noticed the webview retries 15 times to get that image source. I guess after 15 times it stops retrying and loads the rest of the webview.

This happens in both UIWebView and WKWebView. Since the webview still eventually loads, there's no error in the delegate callbacks.

Does anyone know of a way to stop the webview from retrying? Thanks.


Solution

  • I was able to resolve this with UIWebView by implementing NSURLProtocol. I intercepted those bad links and dropped them. The webview now loads a lot faster.

    NSURLProtocol is not supported with WKWebView, however, so this solution won't work for WKWebViews.