• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
WebKit & Caching Data/Stylesheets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

WebKit & Caching Data/Stylesheets


  • Subject: WebKit & Caching Data/Stylesheets
  • From: Oliver Cameron <email@hidden>
  • Date: Sun, 23 May 2004 12:03:57 +0100

Hey guys,

I'm having a few problems with my WebView and caching the data. Basically, I have a HTML editor that has a WebView in it to preview the code. This WebView is updated automatically when a user types in the document text view, so it is essentially live.

For performance reasons, I would like to cache the images in the WebView, so images don't have to constantly reload when a user types.

So in this method:

code:

- (NSURLRequest *)webView:(id)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(id)dataSource

I use this:

code:

if ([[request URL] isEqualTo:baseURL])
{
return request;
}
return [NSURLRequest requestWithURL:[request URL] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:[request timeoutInterval]];

The cache policy I chose seems to be the one I want, here is the description from Apple's docs:

quote:

Specifies that the existing cached data should be used to satisfy the request, regardless of its age or expiration date. If there is no existing data in the cache corresponding the request, the data is loaded from the originating source.

Now, with this I have two problems, firstly, images still reload when I type in my WebView, and secondly, because stylesheets are also being cached, so to activate the changes I make in a stylesheet I have to reopen the application and document. So I decided to use the manual refresh button to clear the cache, and thus load the contents from a fresh (which in theory, should get the newest stylesheet).

So in my refreshManual method:

code:

NSURLCache *cache = [NSURLCache sharedURLCache];
[cache removeAllCachedResponses];
if (inWindowPreview)
[[inWindowPreview mainFrame] loadHTMLString:html baseURL:baseURL];

So, with that, you'd think it would work. Well, it did, kind of. So I loaded up my document with stylesheet, and made changes to the stylesheet externally. I saved the stylesheet, then clicked the refreshManual button, the live preview successfully updated to the new stylesheet. I then made another change in the stylesheet, I then click refreshManual again, but it would not update again. I have no idea why this would work once but not again, since I am clicking the same button that clears out the cache.

Any help at all is appreciated.

Thanks,
Oliver
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: Portability of Foundation & NSObject
  • Next by Date: Re: Avoiding == and = mixup in if statements
  • Previous by thread: NSDrawer Anomolies
  • Next by thread: [OFFish] Performance difference between passing smallish structs by reference or value
  • Index(es):
    • Date
    • Thread