n00b
n00b

Reputation: 16566

CSS Performance

Is there any performance difference between:

p {
  margin:0px;
  padding:0px;
}

and omitting the final semicolon:

p {
  margin:0px;
  padding:0px
}

Thanks in advance!

Upvotes: -1

Views: 288

Answers (5)

BryanH
BryanH

Reputation: 6062

You're actually better off using a CSS minifier. In short, it will remove all of the unnecessary spaces and bloat (e.g., changing #ffffff to #fff where appropriate, removing comments, etc). Some of them will automatically remove the last semicolon in each block. Be aware this can cause issues, as @t-j-crowder mentioned, if you later add lines to the end of the block and forget to add back the semicolon!

Also, make sure you're using external CSS files where possible and store them on the same server/ FQDN. If you can, combine your external CSS files into one so you minimize the number of requests the browser has to make.

This will speed up the download time and give you the biggest bang for your buck in terms of optimization. If the browser caches the files, subsequent visits to the same page (or to different pages using the same stylesheets) will be faster.

Upvotes: 0

John Saman
John Saman

Reputation: 11

I think the main difference will be in the increased css file size. but even if your css file was too big it'll just increase by few bytes. so in short I think it is ok not to care about it.

Upvotes: 1

sundowatch
sundowatch

Reputation: 3103

No, ";" is seperator.

I think we can't talk about performance in CSS.

Upvotes: 0

dicroce
dicroce

Reputation: 46830

I highly doubt it. But, of course, no one has ever measured such a thing independently!

Upvotes: 2

Nick Craver
Nick Craver

Reputation: 630627

No there is not, the browser doesn't care about the trailing semicolon, even in IE6. The parser checks for it as a delimiter that's it.

If anything, since the browser is basically performing tokenization not much more complex than .split(';'), the second may be faster in a probably not measurable way simply because of the lack of an extra null token. But...the difference would be infinitesimal, and you do not need to worry about it either way.

Upvotes: 5

Related Questions