4

I know that one can implement a loading UIView with the usual UIWebView delegate methods webViewDidStartLoad: and webViewDidFinishLoad:

However, this approach means you must wait for ALL images and .gif's to entirely download before removing the loading view. As UIWebView by default asynchronously (lazy) loads images on the page, I'd like to remove the loading view when the page is rendered, but not necessarily wait until the images are all downloaded.

I haven't found any resources on this, but I'm sure it's been done as it's a pretty important optimization. Any ideas?

Erich
  • 2,509
  • 2
  • 21
  • 24

1 Answers1

1

With help from this questions, you can use JavaScript to change the UIWebView's window location right when the DOM is finished loading, like so (jQuery):

$(document).ready(function(){
    location.href = http://removeLoadingScreen
})

Then use the UIWebView delegate method to pick up that link and remove the loading screen:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;

    if([[url absoluteString] isEqualToString:@"http://removeLoadingScreen"]){
        // remove loading screen
    }
}

The images and .gif's won't yet have downloaded, but the rest of the page will be. The one downside is that the space for the images may or may not be blocked yet, so the text content may jump down the page once the images appear.

Community
  • 1
  • 1
Erich
  • 2,509
  • 2
  • 21
  • 24