按字母顺序放置CSS属性有速度好处吗? [英] Are there speed benefits of putting CSS attributes in alphabetical order?

查看:136
本文介绍了按字母顺序放置CSS属性有速度好处吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这个问题不是太奇怪和任意。当我使用Firebug查看一些CSS时,我注意到每个标签的CSS属性是按字母顺序。



它试图告诉我们什么? / p>

除了能够更快找到属性的明显好处,我想知道:如果浏览器应用属性更快在原始样式表中按字母顺序排列?



例如是...

 code> body {
background:#222;
color:#DDD;
font-size:0.85em;
}

#content {
background:#444;
padding:1em;
}

p {
border-bottom:0.9em;
line-height:1.2em;
text-align:justify;
}

...比这更好...?

  body {
font-size:0.85em;
background:#222;
color:#DDD;
}

#content {
padding:1em;
background:#444;
}

p {
text-align:justify;
line-height:1.2em;
border-bottom:0.9em;
}

可以有效地测试吗?



这显然会在整个样式表中被复制,所以浏览器会从顺序做事情中受益,如果是这样,那么值得重新浏览过去的样式表来重新排序。



- 编辑 -



好吧,对我的问题稍有改动:如果每个标签的属性总是以相同的顺序。背景总是在边界之前总是在颜色之前等等(我知道我错过了一些!)为每个标签。按字母顺序排列可以帮助你保持顺序,而不是最佳方法。



看起来压倒性的共识是无关紧要!

解决方案

按字母顺序排序您的样式绝对没有速度的好处。





有这么多的程序可以做,但这里有其中一个: CSSTidy 。这个程序还可以选择按字母顺序排列您的样式(如果您希望您的好处)。


I hope this question isn't too weird and arbitrary. When I'm viewing some CSS using Firebug, I've noticed that the CSS properties for each tag are in alphabetical order.

Is it trying to tell us something?

Apart from the obvious benefit of being able to find the property you're after more quickly, I was wondering this: Is it quicker for a browser to apply the properties if they are in alphabetical order in the original stylesheet?

For example is this...

body {
  background: #222;
  color: #DDD;
  font-size: 0.85em;  
}

#content {
  background: #444;
  padding: 1em;
}

p {
  border-bottom: 0.9em;
  line-height: 1.2em;
  text-align: justify;
}

...better than this...?

body {
  font-size: 0.85em;
  background: #222;
  color: #DDD;  
}

#content {
  padding: 1em;
  background: #444;
}

p {
  text-align: justify;
  line-height: 1.2em;
  border-bottom: 0.9em;
}

Can this be tested effectively?

This would obviously be replicated throughout the entire stylesheet so would a browser benefit from doing things in order and, if so, would it be worth revisiting past stylesheets to reorder things?

-- edit --

Ok, a slight alteration to my question: What if the attributes are always in the same order for each tag. Background always before border always before color etc and so on (I know I've missed some!) for each and every tag. Alphabetical would aid you in keeping things in order rather than being the optimal method.

Looks like the overwhelming consensus is that it matters not, however!

解决方案

There's definitely no speed benefit in ordering your styles alphabetically.

If you want real speed benefits, you should minify your CSS.

There are so many programs to do that, but here's one of them: CSSTidy. This program also has the option to put your styles in alphabetical order (if you want that for your benefit).

这篇关于按字母顺序放置CSS属性有速度好处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆