html - 使用 link 标签或 style 标签导入 CSS 哪个更好?

标签 html css performance

还是只是个人喜好问题?我的意思是,使用这两种方法有特定的好处吗?

<link href="main.css" rel="stylesheet" type="text/css">

对比

<style type="text/css">
@import url('main.css');
</style>

最佳答案

根据雅虎的 Best Practices for Speeding Up Your Web Site , 始终使用 <link>而不是 @import .更多详细信息,请参阅 this blog post .

In IE (tested on 6, 7, and 8), @import causes the stylesheets to be downloaded sequentially. Downloading resources in parallel is key to a faster page. This behavior in IE causes the page to take a longer time to finish.

使用 <link>允许浏览器打开额外的连接,从而减少加载时间。

关于html - 使用 link 标签或 style 标签导入 CSS 哪个更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1495791/

相关文章:

javascript - HTML + JS - 尝试用 div 包围一些用 for 循环创建的内容

javascript - 如何让文本输入框光标在页面加载时自动闪烁?

HTML 和 CSS 表格

c# - 在 C# 中优化列表性能

C++ 指针 vector 如何影响性能?

html - 如何证明和居中我的垂直导航链接

html - 将 JSF HTML5 友好标记与其他组件库一起使用

html - CSS: transform:scale - 带有两个类的 img 标签

javascript - 如何在安卓浏览器中制作滚动条

python - 高效地多处理并发 python 脚本