How to cache content in UIWebView for faster loading later on?

Solution 1:

The key is: NSURLRequestReturnCacheDataElseLoad

NSData *urlData;
NSString *baseURLString =  @"mysite.com";
NSString *urlString = [baseURLString stringByAppendingPathComponent:@"myfile"];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0]; 
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:nil]; 

if (connection)
{ 
    urlData = [NSURLConnection sendSynchronousRequest: request];

    NSString *htmlString = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
    [webView loadHTMLString:htmlString baseURL:baseURLString];
    [htmlString release];
}

[connection release];

Solution 2:

NSString *stringurl=[NSString stringWithFormat:@"http://www.google.com"];
NSURL *url=[NSURL URLWithString:stringurl];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:15.0];
[uiwebview loadRequest:theRequest];

It will load a url first time then looks for for only the content changes..,if there is no updates in the url content it will load from the cache(local storage).