Re: Browsers downloaded linked files regardless of media type

Dynamic changing of the media is of course possible, but it seems completely appropriate to choose not to download the file until it applies. In fact, this would make it very easy to defer loading of stylesheets, although this is not the point.

Should there not be a way to avoid this unnecessary download and the performance hit it implies? Why write a screen stylesheet and a handheld one for performance, if both devices just download everything regardless? Perhaps only download files as necessary, or provide a boolean preload attribute on the link tag.

On 26 Jan 2011, at 17:33, Boris Zbarsky wrote:

> On 1/26/11 2:40 PM, Antony Kennedy wrote:
>> Safari and Firefox (which are the only I've tested so far) both opt to download a file with an unknown or unsupported media type, and then ignore the contents. The spec does not mention at all what the behaviour should be – it only states how the files should be parsed. Regardless of whether the<link>  tag or @import rules are used, the file is still downloaded by the browser.
>> 
>> 	<link rel="stylesheet" href="test.css" media="boat" />
>> 
>> 	@import url(test.css) boat;
>> 
>> Both of these commands will download a file (you can observe this in a proxy, firebug, or the web inspector).
>> 
>> Any performance gain by serving files only to those devices that can make use of them are bypassed in this instance.
>> 
>> Is this a browser bug?
> 
> The problem is that neither the media of the link nor those of the document are fixed.
> 
> So Gecko always downloads stylesheets, independent of the media.  Then we dynamically enable or disable them based on whether the media match the current presentation.
> 
> We could special-case media types we know we don't support, but even then if your script changes the media then suddenly we have to go download the stylesheet... or something.
> 
> Furthermore, there is benefit in having document.stylesSheets and other CSSOM bits not depend on the media types involved (because the alternative is that scripts tested against one medium will throw exceptions in another one); the only way to do that is to download the stylesheets.
> 
> -Boris
> 

Received on Thursday, 27 January 2011 02:00:14 UTC