[webkit-dev] WebKit caching
David Kilzer
ddkilzer at webkit.org
Fri Apr 10 15:17:13 PDT 2009
Why don't you just send a couple HTTP headers with the JavaScript and CSS resources when they leave your web server:
Pragma: no-cache
Cache-Control: no-cache
Or do you need a generalized solution for any web site?
Note that this may not work except in recent nightly builds due to <https://bugs.webkit.org/show_bug.cgi?id=24656>.
Dave
________________________________
From: Adam Thorsen <adam.thorsen at gmail.com>
To: webkit-dev at lists.webkit.org
Sent: Friday, April 10, 2009 12:02:18 PM
Subject: [webkit-dev] WebKit caching
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/b9767762/attachment.html>
More information about the webkit-dev
mailing list