本文介绍了指定媒体之外的LINK样式表是否已加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望LINK标签中定义的设备宽度之外的样式表即使不适用也不会被加载.

I want the stylesheets out of the defined device width defined in a LINK tag not to be even loaded if it doesn't apply.

仅当我知道在解析完其余CSS(包括图像)之后便要导入文件时,才可以从主样式表(用于手持式设备)中将其导入到底部,以导入该文件.

I could import it from the main stylesheet (for handheld devices) by placing the import line at the bottom, only if I knew that file would be imported AFTER the rest of the css has been parsed, including images.

当指定媒体属性时,链接标记的行为是什么?还是不使用它们但还是加载了吗?他们根本没有加载吗? (我希望如此)

So what is the behavior of the link tag when media properties are specified? Are they not used BUT loaded anyway? Are they NOT loaded at all? (what I wish)

谢谢.

推荐答案

浏览器无法假设它从不匹配媒体查询,因此它必须加载样式表以防万一.确实与媒体查询匹配,因此必须使用样式表.这样可以消除与延迟加载相关的任何网络延迟,这些延迟会引起类似于FOUC的问题,在这种情况下,内容在几分之一秒内看起来都不正确(或者,如果连接真的很杂乱,则为几秒钟),因为浏览器在样式表可以使用之前等待加载.

A browser can't assume that it will never match a media query, so it has to load the stylesheet in case it ever does match the media query and has to use the stylesheet as a result. This eliminates any network latency associated with lazy-loading that would cause a problem similar to FOUC, where the content doesn't look right for a fraction of a second (or, if the connection gets really spotty, several seconds) as the browser waits for the stylesheet to be loaded before it can be used.

请注意,@import语句也是如此.但是,该规范不需要浏览器有条件地加载样式表或始终加载样式表.这是依赖于实现的.据我所知,无论使用哪种媒体查询,所有浏览器都将加载样式表.

Note that the same applies with @import statements. The spec however does not require a browser to either load a stylesheet conditionally, or always load it. This is implementation-dependent. As far as I have seen though, all browsers will load a stylesheet anyway regardless of media queries.

在任何规则集之前,除了样式表的开头之外,您都不能在任何位置使用@import语句.

You cannot have an @import statement anywhere other than the beginning of a stylesheet before any rulesets anyway.

这篇关于指定媒体之外的LINK样式表是否已加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 18:43