Need content in UIWebView to display quickly
- by leftspin
Part of my app caches web pages for offline viewing. To do that, I am
saving the HTML fetched from a site and rewriting img urls to point to
a file on the local store. When I load the html into a UIWebView, it
loads the images as expected and everything's fine. I am also caching
stylesheets in this fashion.
The problem is that when I put the phone into airplane mode, loading
this cached html causes the UIWebView to display a blank screen and
pause for a while before displaying the page. I've figured out that
it's caused by non-cached URLs referenced from the original HTML doc that
the web view is trying to fetch. These other URLs include images within
the cached stylesheets, content in iframes, and javascript that opens a
connection to fetch other resources. The pause happens when the
UIWebView tries to fetch these resources, and the web page only appears after all these other fetches have timed out.
My questions is, how can I make UIWebView just display the stuff I've
cached immediately? Here are my thoughts:
write even more code to cache these other references. This is
potentially a ton more code to catch all the edge cases, etc., especially having to parse the Javascript to see what it loads after the page is loaded
force UIWebView to time out immediately so there's no pause. I
haven't figured out how to do this.
somehow get what's already loaded to display even though the external references haven't finished fetching yet
strip the code of all scripts, link tags and iframes to "erase" the
external references. I've tried this one, but for some sites, the
resultant page is severely messed up
Can anyone help me here? I've been working on this forever, and am
running out of ideas.