[webkit-dev] WebKit caching
Adam Thorsen
adam.thorsen at gmail.com
Fri Apr 10 12:02:18 PDT 2009
I would like to prevent a WebKit WebView instance in Cocoa from
caching certain content. I've attempted to prevent this using several
approaches, including:
1. Overriding the NSURLCache cachedResponseForRequest and
cachedResponse forRequest methods
2. Handling -(NSURLRequest *)webView:(WebView *)sender resource:(id)
willSendRequest:(NSURLRequest *) redirectResponse:(NSURLResponse *)
fromDataSource:(WebDataSource *)dataSource
a) tried setting the cache policy to
NSURLRequestReloadIgnoringCacheData, among other settings
b) tried appending a random string onto the end of the
resource url before passing it along (i.e. something like http://blah.com/file.js?23234234234)
3. Clearing the cache by setting the shared url cache (via
NSURLCache ) and calling removeAllCachedResponses before each page load.
4. Setting preferences on the WebView:
WebPreferences *prefs = [webView preferences];
[prefs setUsesPageCache:NO];
and
WebPreferences *prefs = [webView preferences];
[prefs setPrivateBrowsingEnabled:YES];
None of these approaches seem to prevent the webview from caching
javascript resources. Based on its behavior, I believe that on
initial page load it checks the last-modified value in each response
header and caches resources in memory that have not been modified
within a certain period of time. Recently modified files (within the
past few minutes) are not cached.
My ultimate goal is simply to prevent the webview from caching
javascript and css files, and I am open to any suggestions on how to
do that. However, based on my above hypothesis about how WebKit
handles caching internally, I believe that if I could rewrite the
response headers such that last-modified is always a recent value, I
could prevent WebKit from caching.
Currently I can view the response header by implementing:
- (void)webView:(WebView *)sender resource:(id)identifier
didReceiveResponse:(NSURLResponse *)response fromDataSource:
(WebDataSource *)dataSource
and calling allHeaderFields on the response. However, there appears
to be no way to modify the response before sending it on to the
webview for display. Are there any suggestions on how to do this?
Thanks,
-Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090410/aaf907e4/attachment.html>
More information about the webkit-dev
mailing list