`
deng131
  • 浏览: 673507 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

IE浏览器stylesheets加载资源限制问题

阅读更多
@import url()做一下总结:

1:@import url()机制是不同于link的,link是在加载页面前把css加载完毕,而@import url()则是读取完文件后在加载,所以会出现一开始没有css样式,闪烁一下出现样式后的页面(网速慢的情况下)。

2:@import 是css2里面的,所以古老的ie5不支持。

3:当使用javascript控制dom去改变样式的时候,只能使用link标签,因为@import不是dom可以控制的。

4:link除了能加载css外还能定义RSS,定义rel连接属性,@import只能加载css

@import url(xxx.css); 有最大次数的限制,经测试IE6的最大次数是31次,第32个import及
虽然最多只能import 31次,但不会影响css里面的其他规则,如body{}的定义还能正常显示。
Firefox 没有发现有import的最大值。

引用

31 stylesheets per file

If you are an ASP.NET developer and you develop mid-sized projects using App_Themes the chances are that you will hit this limit sooner than later. The problem is that App_Themes engine iterates through the skin folder and loads every CSS file kept in there regardless if it is needed or not. Every Internet Explorer version (including IE8 and unfortunately the IE9 preview released recently) on the other hand has the limit of loading only 31! stylesheets per file and thus fails to load all CSS files in a theme if they are more than 31. Another thing is that style tags in the HTML head or body are also counted as stylesheets (they are in fact parsed and created as different stylesheet objects) and are contributing to the problem - the more style tags you have, the less stylesheets you can include.

Unfortunately this bug is transferred to our RadControls as well. If you use a big number of RadControls and custom skins for them in a theme and just dump all the CSS files in it, you are in trouble.

Click here for a demo of a broken project which fails to load its CSS in all IE browsers. You can find the original project zipped at the end of this blog post.

There are several ways to fix the issue. One of them is to add a RadStyleSheetManager to your page - it has a stylesheet combining feature which is switched on by default and that will help you to partially reduce the number of loaded CSS files. However this method fixes the issue only to an extent (combines only the non-external skins) and may lead you to the second CSS limit in Internet Explorer which we will discuss soon enough.

Fortunately there is an alternative solution - it involves removing all the stylesheets from the App_Themes folder, moving them somewhere else within the site and creating there one or several CSS files in which you link the removed CSS files one by one using @import declarations.

Click here for a demo of a fixed site using the latter method. A zip with the original is awaiting you at the end of the article.

4095 selectors in a CSS file

A little less known limitation in all Internet Explorer browsers is the maximum number of possible selectors in a CSS file - 4095. This means that if you stumble upon the 31 stylesheets bug and decide to combine all your stylesheets to avoid it - at the end you will probably be in similar situation as in the beginning.

Unfortunately the only fix for this is splitting the file to several different CSS files and using the described above @import method to include them in your project.

Click here to see a test case of this bug or download the source below.


http://stackoverflow.com/questions/3211991/does-ie-8-have-a-limit-on-number-of-stylesheets-per-page
http://blogs.telerik.com/aspnetmvcteam/posts/10-05-03/internet-explorer-css-limits.aspx
分享到:
评论

相关推荐

    圆角用资源

    标题“圆角用资源”和描述中提到的“低版ie下实现圆角,类css3的功能”,指的是针对这些老版本IE浏览器实现CSS3圆角边框的解决方案。 CSS3的圆角边框可以通过`border-radius`属性来实现,这使得元素的四角可以变得...

    面试宝典 v2-新增Vue和React.pdf

    3. Quirks模式与Standards模式:Quirks模式模拟老版本IE浏览器的行为,而Standards模式遵循最新的W3C标准,两者在渲染和行为上存在差异。 4. div+css布局优于table布局:div+css更灵活,可维护性更强,有利于SEO,...

    虚拟WEB桌面.zip

    4. **跨平台兼容性**:由于依赖于浏览器的支持,虚拟WEB桌面需要考虑不同浏览器的兼容性问题,可能需要对老旧的IE浏览器进行特殊处理,或者利用polyfill库来提供缺失的API。 5. **安全性和性能**:由于在用户端运行...

    浏览器测试页面

    各个浏览器对JS的执行环境和API支持可能存在差异,例如IE浏览器对ES6新特性支持较弱,而现代浏览器如Chrome、Firefox则支持得更好。测试页面应包含各种JS语法和API,确保它们能在所有目标浏览器上正常运行。 4. ...

    *.htc 文件的简单介绍

    `.htc` 文件,全称为“HTML Component”,是微软在Internet Explorer浏览器中引入的一种特性,主要用于CSS(Cascading Style Sheets)扩展,特别是在IE浏览器的版本中。它允许开发者使用脚本语言(如JavaScript或...

    AJAX开发简略(PDF)

    - **浏览器兼容性**:早期版本的IE浏览器对AJAX支持不完全,但现在大多数现代浏览器都支持。可以通过引入jQuery或其他库解决。 - **SEO问题**:搜索引擎爬虫可能无法执行JavaScript,导致AJAX加载的内容无法被索引。...

    JavaScript实现动态创建CSS样式规则方案

    另外,早期版本的IE浏览器中Stylesheets的insertRule方法不可用,这需要我们采取一些特定的兼容性处理策略。 此外,文章还提到了一种创建新样式表的方法,就是通过编程方式动态创建<style>元素并将其添加到页面的...

    只需20行代码就可以写出CSS覆盖率测试脚本

    对于不支持`styleSheets`属性的旧版IE浏览器,可以尝试使用expression或behavior.htc作为替代方案,但这可能涉及更多的兼容性问题。 总的来说,这个简单的CSS覆盖率测试脚本提供了一种快速评估和优化前端代码的方法...

    浅谈css和@import区别及用法

    例如,早期的IE浏览器就不支持`@import`。 4. 与JavaScript交互的区别: - 通过`<link>`标签引入的样式表可以通过JavaScript(例如,使用document.styleSheets)获取并动态修改。 - `@import`由于是在CSS层面解析...

Global site tag (gtag.js) - Google Analytics