Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS Performance Tuning

CSS Performance Tuning

CSS is often overlooked when it comes to performance optimizations, however when your site starts receiving a high amount of traffic, or you build a web application to handle high load scenarios, it may be useful to dig deeper and get the most out of every piece of your setup.

Jakub Pawlowicz

May 06, 2015
Tweet

More Decks by Jakub Pawlowicz

Other Decks in Technology

Transcript

  1. whitespace*removal a:before { display: none } div { margin: 0

    } => a:before{display:none}div{margin:0}
  2. unit%op(miza(ons a { color: #ff0000 } div { margin: 1px

    2px 0px 1px } => a{color:red}div{margin:1px 2px 0 1px}
  3. and$addi&onally$offers... • content'restructuring'&'@media'merging • URL'rebasing'&'rewri7ng • local'&'remote'@import'inlining • source'maps'(since'version'3.0) •

    2xB10x'speedup'over'comparable'op7mizers • good'test'coverage'with'over'2.5k'tests • compa7bility'modes'(IE7,'IE8,'granular'level)
  4. .foo { margin: 20em; margin: 20vw; } .bar { display:

    block } .foo { padding: 10px; } => .foo{margin:20vw;padding:10px} .bar{display:block} In#IE8#mode#the#unit#fallback#would#stay#as#it#is
  5. .foo { background: url('data:image/jpeg;base64,...'); width: 100px; } .bar { display:

    block; } .baz { background: url('data:image/jpeg;base64,...'); width: 110px; } => .baz,.foo{background:url('data:image/jpeg;base64,...')} .foo{width:100px} .bar{display:block} .baz{width:110px} Changing'last'line'to'baz:last-child'in'IE8'mode' would'not'collapse'rules'as'IE8'doesn't'understand' this'pseudo8selector
  6. .foo { margin-top: 0; } @media screen { .foo {

    margin-bottom: 0; } } .bar { display: block; margin-top: 0; } => .bar,.foo{margin-top:0} @media screen{.foo{margin-bottom:0}} .bar{display:block} We#can#move#margin-top:0#over#a#@media#block# since#it#does#not#redefine#margin-top#value
  7. .foo { background: red; background-image: url(image.png); background-repeat: repeat; background-position: top

    left; margin: 20px; margin-top: 1px; } => .foo{ background:url(image.png) top left red; margin:1px 20px 20px } clean&css(also(knows(how(to(merge(shorthand(and( longhand(proper3es(together,(and(when(not(to(do(it(&( replace(url()(with(linear&gradient()(and(it(won't
  8. SSL

  9. Delivery • ✔"CSS"split"into"mul.ple"files • ✔"caching"headers • ✔"compressed"assets • ✔"dedicated"mobile"site,"no"deferred"content •

    :"could"use"higher"gzip"compression"or"zopfli • ✖"missing"caching"headers"for"desktop"site"content