简体   繁体   English

CSS - 哪些代码渲染速度更快,效率更高?

[英]CSS - which code renders faster and is more efficient?

I would like to know which of below codes renders faster and is more efficient: 我想知道以下哪些代码渲染速度更快,效率更高:

This - 这个 -

body{background:#ddd;font-family:verdana;font-size:12px;color:#808080;}
a{color:#808080;outline:0;text-decoration:none;}
input{margin:0;padding:0;font-family:verdana;color:#808080;}
ul{padding:0;margin:0;}

Or this - 或这个 -

body,input{font-family:verdana}
body,input,a{color:#808080;}
body{background:#ddd;;font-size:12px;}
a{outline:0;text-decoration:none;}
input,ul{margin:0;padding:0;}

Efficiency is irrelevant here. 效率与此无关。

Go with whichever is easier to read/understand/maintain, which is clearly the first snippet. 选择更易于阅读/理解/维护的内容,这显然是第一个片段。

However, that second snippet looks like it's been minified , which is a good thing to do, because it reduces the transfer size of the CSS - it doesn't improve the "rendering speed". 然而,第二个片段看起来像是缩小了 ,这是一件好事,因为它减少了CSS的传输大小 - 它不会提高“渲染速度”。

You should write your CSS in the most understandable way, then generate a minified version when you put it live. 您应该以最易理解的方式编写CSS,然后在生成时生成缩小版本。

I have never seen any performance issue with CSS, except one thing. 除了一件事,我从未见过CSS的任何性能问题。 When you use * in some cases your JavaScript can become very slow. 当你在某些情况下使用* ,你的JavaScript会变得很慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM