iPhone UIWebView slow loading to local HTML files

Mina Mikhael picture Mina Mikhael · Jan 6, 2010 · Viewed 20.6k times · Source

I'm developing an app that requires caching web pages (completely) along with their CSS files and images after saving the entire HTML of the page (going through the links to store each file along with the HTML file).

While viewing the HTML file offline, UIWebView takes a long time to load the page, given that I'm already offline, and the file is on disk along with its CSS and images.

I'm using this code to load the file:

  NSData *htmlData = [NSData dataWithContentsOfFile:htmlFilePath];
  [wView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:self.htmlFolderPath isDirectory:YES]];

Is there any other means of loading the file to the UIWebView that can load it faster?

P.S: it loads very fast on simulator (offline) but on device it takes a long time (considering its an already offline cached file)

Thanks for help.

Answer

ACBurk picture ACBurk · Aug 3, 2010

Is your solution actually cache things other than the html file, meaning pictures, css, etc, AND relinking them in the html page? I am guessing that you are downloading and caching the html page and external resources then the UIWebView is loading that html and still going out to load the external resources. That would explain the fast performance on the simulator and the slower performance on device.

Here is a library designed to do exactly what you are trying to do: ASIWebPageRequest.

It should also be noted that it could simply be a case of disk i/o bottlenecking. I know on my project, I was loading large images in a uitableview and even after they were cached I noticed quite a bit of lag when pulling them off the disk because they were so big.