为什么所有浏览器都下载所有CSS文件 - 即使是他们不支持的媒体类型? [英] Why do all browsers download all CSS files - even for media types they don't support?
问题描述
如果我指定一个不支持的媒体类型(bork
)的CSS链接,它仍然会被我试过的每个浏览器下载(包括桌面和几个移动浏览器)。
< link href =bork.cssmedia =bork =stylesheettype = text / css/>
并且变得更糟...
如果文件bork.css @import
是第二个CSS文件也被下载的其他CSS文件(也包含不支持的媒体类型)。
/ *内部bork.css* /
@import url(bork2.css)bork,博克
为什么?
某些浏览器可能正在搜索它们支持的媒体类型的嵌套 @import
s或 @media
然后应用这些文件中包含的样式规则...
/ *在bork2.css* /
@import url(all.css);
@media all {
/ * rules * /
}
...但是到目前为止我可以告诉,不是一个单一的浏览器。 (幸运的是,这将是一个错误。)
因此,所有这些下载似乎完全多余 - 除非有一些我一直错过的解释。
编辑:我想要了解的是激励浏览器制造商去:
嘿!让我们下载一堆CSS文件,我们没有打算申请,并停止加载其他资源同时!
浏览器允许并鼓励解析 / code>描述符 - 无论是什么描述符 - 作为一种方式使它们变得友好
未来版本的HTML可能引入
新值,并允许参数化
值。
* From:http://www.w3.org/TR/html4/types.html#h-6.13
这样,媒体可能有一天包括 3d眼镜
或其他描述符,包括 bork
; - )
EDIT:
在媒体查询中说,这在一定程度上支持上述内容:
未知媒体
类型计算为false。有效地,
他们被视为与设备的
媒体类型不匹配的已知
媒体类型相同。
*:: http://dev.w3.org/csswg/css3- mediaqueries /#error-handling
因此,它们被视为已知且已下载以供使用,而不是当时/用于该设备。
If I specify a CSS link with an unsupported media type ("bork"
) it still gets downloaded by every browser I've tried (including both desktop and several mobile browsers).
<link href="bork.css" media="bork" rel="stylesheet" type="text/css" />
And it gets worse...
If the file bork.css @import
s an other CSS file (also with an unsupported media type) that second CSS file also gets downloaded.
/* Inside "bork.css" */
@import url("bork2.css") bork, bork;
Why!?
My first assumption was that some browsers might be searching for nested @import
s or @media
blocks with media types that they supported - and then apply the styling rules contained within those files...
/* Inside "bork2.css" */
@import url("all.css");
@media all {
/* rules */
}
...but as far s I can tell, not a single browser does that. (Fortunately, as that would be a bug.)
So all this downloading seems wholly redundant - unless there's some explanation that I've missed all along.
EDIT: What I'm trying to understand is that motivates browser makers to go:
"Hey! We're trying to make our browser crazy fast! Let's download a bunch of CSS files that we have no intention of applying, and halt the loading of other resources meanwhile!"
I think the answer is this:
Browsers are allowed and encouraged to parse media
descriptors - no matter what the descriptor - as a way to make them future friendly
Future versions of HTML may introduce new values and may allow parameterized values.
*From: http://www.w3.org/TR/html4/types.html#h-6.13
In this way, media may one day include 3d-glasses
or other descriptors, including bork
;-)
EDIT:
The latest CSS3 spec on media queries says this, which supports the above, to a certain degree:
Unknown media types evaluate to false. Effectively, they are treated identically to known media types that do not match the media type of the device.
*From: http://dev.w3.org/csswg/css3-mediaqueries/#error-handling
So they are treated as known and downloaded to be used, just not at that time/for that device.
这篇关于为什么所有浏览器都下载所有CSS文件 - 即使是他们不支持的媒体类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!