Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WebView resource loading



Rob Keniger wrote:

On Aug 24, 2007, at 1:50 AM, Rush Manbert wrote:

If you are doing this so that you can return different data at different times for the same resource URL in the page, then you have a problem. (For example, your page contains the element <img href="MyImage.gif" /> and when you see the "MyImage.gif" URL you look at some data and decide what picture you should really display, and it can be a different picture every time.) The problem is not in the currently shipping WebKit, but it is in the nightly builds and, I assume, will be in the WebKit that supports Safari 3 and ships with Leopard. What happens is that when page resources are loaded, their data is cached, and the cached data is keyed by the original URL. This means that whatever data you return the first time you intercept that URL will be used subsequently. Your webView:resource:willSendRequest:redirectResponse:fromDataSource: delegate will only be called the first time, and the data will be read from cache after that.

I ran across this when my resources were all file:/// URLs, and it also occurred when I switched everything to use my own custom protocol. My protocol loader only got called the first time, but not subsequently for the same original resource URL. It also did not seem to matter that I specified no caching in my NSURLResponse that I used to return the data. It was cached anyway.


Yes, I definitely see this as well and it has been mentioned several times on this list before. The only way I have been able to work around it is to manually add dummy arguments to the end of the url, e.g.: myprotocol:///myspecialresource?arandomNumber12345

This prevents caching but it is incredibly hacky. There needs to be a way to specify that resources should *never* be cached. I have tried absolutely everything I could think of and scoured all the resources on the web I could find and this is the only solution that works.


It's good to hear from someone else who has to deal with this problem. In my case I intercept the willSendRequest call and render the XHTML source files into a HTML string that I attach to the new NSURLRequest that uses my custom protocol. It is possible for me to resolve the resource reference URLs while I am creating the HTML string, but it means that I have to find all of the element attributes that are used that way and discriminate the cases where the same attribute name is used in multiple elements while being a resource reference in one some cases, etc. I also have a problem if my JavaScript generates a resource URL because I can't find those by walking the DOM tree.


I have filed bug reports on this at webkit.org and at Apple, but there has been no action. Either the caching needs to be fixed (but it looks like it's a major change to the caching algorithm to do that) or we need to be able to turn off caching for page resources.

Of course, even if that were to happen, you get into trouble if your resource URLs are written as if they were relative, because the newest WebKit doesn't let you control the base URL when you load with your custom protocol. It uses the custom protocol URL. That's a big problem for my app and is another thing forcing me to resolve the URLs early, and it is a change from the current WebKit behavior. Another bug filed.

- Rush
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webkitsdk-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webkitsdk-dev/email@hidden

This email sent to email@hidden
References: 
 >WebView resource loading (From: Mike Gargano <email@hidden>)
 >Re: WebView resource loading (From: Rudi Sherry <email@hidden>)
 >Re: WebView resource loading (From: Rob Keniger <email@hidden>)
 >Re: WebView resource loading (From: Rush Manbert <email@hidden>)
 >Re: WebView resource loading (From: Rob Keniger <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.