Re: NSAttributedString from html weirdness
Izidor Jerebic <[email protected]> Sun, 3 Oct 2010 10:13:18 +0200
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
I had to prevent css cacheing for app since 10.3 and below is the code it uses. It should be put in applicationWillFinishLaunching: delegate method. Beware, it is hacky, but it works for me:
[NSURLCache setSharedURLCache:[[MyURLCacheIgnore alloc] init]] ; // no cacheing whatsoever!!!!
// hack to prevent WebView from cacheing CSS stylesheets
{
id wcc ;
wcc = NSClassFromString(@"WebCoreCache") ;
if( wcc == nil ) {
// try for Leopard WebKit
wcc = NSClassFromString(@"WebCache") ;
}
if( [wcc respondsToSelector:@selector(setDisabled:)] ) {
[wcc setDisabled:YES] ;
}
}
And implementation of MyURLCacheIgnore is simple as well:
@implementation MyURLCacheIgnore
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
{
return nil ;
}
- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request
{
}
@end
izidor
On 2.10.2010, at 11:13, Christiaan Hofman wrote:
>
> On Oct 2, 2010, at 10:19, Izidor Jerebic wrote:
>
>>
>> This sounds like WebKit caching the css, and when reading html file, the cached css is applied. In your case, the easiest way to prevent caching is to append some random number to the css file name, so you create css file with unique name every time.
>>
>> izidor
>>
>
> Yes, that's what I also expect. I cannot change the css file name though, because it's hard coded in the HTML, and I don't directly control that. Would anyone know of another way to reset this cache?
>
> Christiaan
>
>>
>> On 2.10.2010, at 2:11, Christiaan Hofman wrote:
>>
>>> I'm getting a very weird problem when trying to create an NSAttributedString from a (temporary) html file with an external css file. Basically what happens is that the attributed string always keeps on using the same css file content, even if I change the css file completely.
>>>
>>> Here's a more detailed description of what I'm doing.
>>>
>>> 1. create a temporary directory
>>> 2. write a (code generated) html file and css file used by that html file into this temp dir
>>> 3. create a new NSAttributedString from the html file URL
>>> 4. remove the temp dir
>>>
>>> When I repeat the same procedure with /different/ css, then I get an attributed string that uses the style described with the /first/ css file (even though that file does not even exist anymore). This is very weird. However, changes in the html file are properly reflected in the NSAttributedString.
>>>
>>> Can anyone make sense out of what is happening? It certainly makes absolutely no sense to me, but it's absolutely reproducible. Is this a (known) bug?
>>>
>>> thanks,
>>> Christiaan
>>>
>>> _______________________________________________
>>> MacOSX-dev mailing list
>>> [email protected]
>>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>>
>> _______________________________________________
>> MacOSX-dev mailing list
>> [email protected]
>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>