SlideShare a Scribd company logo
1 of 92
CSS BLOAT!
                             with Nicole Sullivan




Friday, September 10, 2010
TWEET!


                             @stubbornella




Friday, September 10, 2010
WHY OPTIMIZE CSS?


    • It blocks progressive rendering
     
 test: http://www.phpied.com/files/css-loading/table.php
    • It’s verbose (property value pairs cannot be minified like JS)
     
              text-decoration: underline
 != td: u


Friday, September 10, 2010
TOP 1000 STUDY


    1. Grab top Alexa sites
    2. Start Fiddler
    3. Load each site
    4. Export from Fiddler



Friday, September 10, 2010
<?php

         $file = file('alexa.txt');

         foreach ($file as $url) {

                  launch($url);

         }

         function launch($url) {

                  try {

                             $ie = new COM("InternetExplorer.Application");

                             $ie->Visible = true;

                             $ie->Navigate2($url);

                             while ($ie->ReadyState != 4) sleep(1);

                             $ie->Quit();

                  } catch (Exception $e) {}

         }

         ?>
Friday, September 10, 2010
42% DON’T GZIP CSS




Friday, September 10, 2010
44% HAVE MORE THAN 2
                 CSS FILES
                             56%

                                   44%




Friday, September 10, 2010
56% SERVE CSS WITH
                            COOKIES




Friday, September 10, 2010
62% DON’T MINIFY




         would get more than 10% savings from YUI compressor
Friday, September 10, 2010
21% HAVE >100K OF CSS
                                   21%


                             11%
                             11%


                                          44%


                                    24%
Friday, September 10, 2010
HASTE TRACE-BASED PACKAGING




                                                            homepage     homepage
              Date           CSS files          CSS weight
                                                              files         weight

       Nov 2008                487                  1.7MB      24            69KB

        May 2009               706                  1.9MB      15            64KB

   http://velocityconference.blip.tv/file/2293221/               David Wei & Changhao Jiang
Friday, September 10, 2010
KUDZU
      Was introduced to the United States between 1935 and 1950
       by the Soil Conservation Service to prevent soil erosion.


Friday, September 10, 2010
CSS KUDZU!


Friday, September 10, 2010
“OBJECT ORIENTED CSS
                   SOUNDS GREAT, BUT WE
                    HAVE A GIANT MESS!”
                             how do we get from here to there?




Friday, September 10, 2010
FACEBOOK DECIDED TO
                  GO ON A DIET
                             The CSS was one piece of the puzzle




Friday, September 10, 2010
Jason Sobel -
                             Perf Manager Fu

                               MANY PIECES                    Nan Gao
  Kyle Delong - PHP                  David Wei & Changhao Jiang BigPipe




            Marcel
            Laverdet -                         Tom Occhino - JS
            XHP
     Makinde                                 Shaun McIntyre -
     Adeagbo - JS                          Automated Spriting
Friday, September 10, 2010
THEY REDUCED THEIR
            RESPONSE TIME BY HALF
                             in only six months




Friday, September 10, 2010
WHAT IS OBJECT
                             ORIENTED CSS?
                             A philosophy? A framework? A tool?




Friday, September 10, 2010
MORE LIKE AN EVOLUTION
      OF THE LANGUAGE
                             it makes CSS more powerful




Friday, September 10, 2010
HOW IS IT DIFFERENT?


                                  ul{...}
                               ul li{...}
                             ul li a{...}




Friday, September 10, 2010
HOW IS IT DIFFERENT?


                                  ul{...}
                               ul li{...}
                             ul li a{...}



   Until now, we focused all our effort here

Friday, September 10, 2010
HOW IS IT DIFFERENT?


                                     ul{...}
                                  ul li{...}
                                ul li a{...}



                  But, the architecture lives here

Friday, September 10, 2010
MUCH LESS CODE
                               easier to work with newbies




Friday, September 10, 2010
GRIDS
    •   574 bytes

    •   14 lines of code

    •   Percentage widths adapt to
        different page sizes

    •   Includes halfs, thirds, fourths, and
        fifths

    •   No gutters

    •   Infinite nesting and stacking

Friday, September 10, 2010
GRANULARITY FAIL
                            + STALE RULES
                         + UNPREDICTABILITY
                           + DUPLICATION
                         + SPECIFICITY WARS
                           = MASSIVE CSS
Friday, September 10, 2010
5              Text


                             GRANULARITY FAIL
                       the CSS objects shouldn’t match the PHP objects



Friday, September 10, 2010
Friday, September 10, 2010
Friday, September 10, 2010
Friday, September 10, 2010
http://www.brickartist.com/
Friday, September 10, 2010
http://www.brickartist.com/
Friday, September 10, 2010
WE WANT TO DO THE
                SAME THING WITH CSS




Friday, September 10, 2010
CREATE THE
                             BUILDING BLOCKS




Friday, September 10, 2010
MOST SITES GET THE
               GRANULARITY WRONG
                             and their architecture is set up to fail




Friday, September 10, 2010
HOW? FIRST, A VISUAL
                     INVENTORY




Friday, September 10, 2010
TAKE A PHP OBJECT
Friday, September 10, 2010
BREAK IT DOWN
Friday, September 10, 2010
7 SMALLER OBJECTS




Friday, September 10, 2010
headings




Friday, September 10, 2010
HEADINGS
   Heading      - 16px bold #3B5998
   Heading     - 16px normal #333333
   Heading     - 15px bold #3B5998     • 12px   headings eliminated
   Heading     - 15px normal #333333
   Heading     - 14px bold #3B5998     • Blue   only for links
   Heading    - 14px normal #333333
   Heading    - 13px bold #3B5998      • Bold   for all titles
   Heading    - 13px normal #333333    • Chad Little went through
   Heading   - 11px bold #3B5998        the entire site eliminating
   Heading   - 11px normal #333333      duplicates.
Friday, September 10, 2010
IT’S ALL ABOUT PATTERN
                    MATCHING
                             but you have to take a step back




Friday, September 10, 2010
PHP OBJECTS != CSS OBJECTS
                             you will be tempted, beware!




Friday, September 10, 2010
4        Text


                             STALE RULES
                                 CSS gets crufty



Friday, September 10, 2010
STALE IS TWO THINGS



    ❖   Truly stale - rules that are no longer used on the site
    ❖   Rules used on subsequent PV or activated on user action




Friday, September 10, 2010
WHAT KIND DO YOU
                            HAVE?




Friday, September 10, 2010
WHAT KIND DO YOU
                            HAVE?


    ❖   Try dust-me selectors




Friday, September 10, 2010
WHAT KIND DO YOU
                            HAVE?


    ❖   Try dust-me selectors
    ❖   Track them over time -
         ‣   changes are more important than an absolute number




Friday, September 10, 2010
3         Text


                             UNPREDICTABILITY
               Make each object predictable and location independent



Friday, September 10, 2010
h3




Friday, September 10, 2010
h3




Friday, September 10, 2010
A        Heading should not become a          Heading

                                   in another part of the page.




Friday, September 10, 2010
AVOID
                                    EXAMPLE
                             #weatherModule h3{color:red;}
                             #tabs h3{color:blue}


    ❖   Global color undefined for h3, so it will be
         ‣   unstyled in new modules,
         ‣   developers forced to write more CSS for the same style




Friday, September 10, 2010
HOW DO YOU TEST FOR
             UNPREDICTABLE CODE?
                             #foo h3{...}
                             #bar h3{...}
                             #baz h3{...}

                             grep
                             h[1-6]



Friday, September 10, 2010
h1-h6
                     How many? You need site-wide headings




Friday, September 10, 2010
511
                             declarations setting styles for h1-h6


  56% >10
  9% >100
Friday, September 10, 2010
HEADINGS BEFORE



                               958
                                 declarations h1-h6



                                                      Facebook
Friday, September 10, 2010
HEADINGS AFTER:



                                 25
                                       Chad Little - Facebook
Friday, September 10, 2010
2                   Text


                              SPECIFICITY WARS
                             lobbing specificity grenades over the cube wall



Friday, September 10, 2010
SPECIFICITY SCREWS UP
                   THE CASCADE
                        and the cascade kind of rocks, so how do we use
                                        the good parts?




Friday, September 10, 2010
SIMPLIFY SPECIFICITY




Friday, September 10, 2010
.mod .hd{...}
.ie .mod .hd{...}
.weatherMod .hd {...}




                 USE HACKS SPARINGLY
                             And don’t let them change your specificity




Friday, September 10, 2010
.mod .hd{...}
           X
.ie .mod .hd{...}
.weatherMod .hd {...}




                 USE HACKS SPARINGLY
                             And don’t let them change your specificity



                         .mod .hd{color: red; _zoom:1;}
                         .weatherMod .hd{...}

Friday, September 10, 2010
#navigation{...}
    #header{...}




                             AVOID STYLING IDS
                             IDs impact specificity and can’t be reused




 IDs are for JS
Friday, September 10, 2010
X
    #navigation{...}
    #header{...}




                             AVOID STYLING IDS
                             IDs impact specificity and can’t be reused




 IDs are for JS
Friday, September 10, 2010
.nav {color: red !important;}




                             AVOID !IMPORTANT
                                 except on leaf nodes




Friday, September 10, 2010
.nav {color: red !important;}      X

                             AVOID !IMPORTANT
                                 except on leaf nodes




Friday, September 10, 2010
!IMPORTANT



                              518
                             declarations using important



 12% have greater than 50
Friday, September 10, 2010
div.error{...}




                             STYLE CLASSES
                               rather than elements




Friday, September 10, 2010
X
              div.error{...}




                             STYLE CLASSES
                               rather than elements


                  .error{        most of the code goes here   }



Friday, September 10, 2010
X
              div.error{...}




                             STYLE CLASSES
                               rather than elements


        .error{                  most of the code goes here   }
     div.error{                                               }
       p.error{                         exceptions only       }
      em.error{                                               }
Friday, September 10, 2010
html body .myModule div .hd{...}
.myModule2 .hd {...}


                                 GIVE RULES THE
                                SAME STRENGTH
                             Use cascade order to overwrite previous rules




Friday, September 10, 2010
X
html body .myModule div .hd{...}
.myModule2 .hd {...}


                                 GIVE RULES THE
                                SAME STRENGTH
                             Use cascade order to overwrite previous rules



                         .myModule .hd{...}
                         .myModule2 .hd{...}

Friday, September 10, 2010
1           Text


                             DUPLICATION
                                 CSS kudzu on steroids



Friday, September 10, 2010
GREP IS YOUR FRIEND
                    look at the stylesheets globally rather than per page




Friday, September 10, 2010
margin  too many? You need reset.css




Friday, September 10, 2010
518
                             declarations reset margin to zero


  64% > 10
 14% > 100
Friday, September 10, 2010
float
                             too many? You need grids




Friday, September 10, 2010
733
                             declarations floated elements


  56% > 10
 13% > 100
Friday, September 10, 2010
font-size               headings may be disguised in class names




Friday, September 10, 2010
FONT-SIZE



                                889
                             declarations changed the font-size


 78% >10
 23% >100
Friday, September 10, 2010
HOW DID FACEBOOK
                REDUCE DUPLICATION?
                             let’s look at an example




Friday, September 10, 2010
MEDIA BLOCK EXAMPLE




Friday, September 10, 2010
ALL OF THESE ARE THE
                       SAME OBJECT




Friday, September 10, 2010
WHAT DO WE KNOW?

                             ❖ Can be nested
                             ❖ Optional right button

                             ❖ Must clearfix




Friday, September 10, 2010
WHAT DON’T WE KNOW?

                             ❖ Image width and decoration vary
                             ❖ Right content is unknown

                             ❖ Width unknown




Friday, September 10, 2010
SEPARATE STRUCTURE
                        FROM CHROME




Friday, September 10, 2010
A FEW LINES OF HTML...

            <div class="media attribution">
              <a href="http://twitter.com/stubbornella" class="img">
                <img src="mini.jpg" alt="Stubbornella" />
              </a>
              <div class="bd">@Stubbornella 14 minutes ago</div>
            </div>




Friday, September 10, 2010
4 LINES OF CSS...


                                   _




Friday, September 10, 2010
Friday, September 10, 2010
HTML SIZE
                      reduced by 50%




                                   by Stefan Parker
Friday, September 10, 2010
“Due to these efforts, we cut our average
            CSS bytes per page by 19% (after gzip) and
            HTML bytes per page by 44% (before
            gzip).”



                             Jason Sobel
                             http://www.facebook.com/note.php?note_id=307069903919
Friday, September 10, 2010
LET’S KEEP TALKING...
                                  www.stubbornella.org
                                    @stubbornella




                 OOCSS Project: http://github.com/stubbornella/oocss/

Friday, September 10, 2010

More Related Content

What's hot

Pgday bdr 천정대
Pgday bdr 천정대Pgday bdr 천정대
Pgday bdr 천정대PgDay.Seoul
 
BEM it! Introduction to BEM
BEM it! Introduction to BEMBEM it! Introduction to BEM
BEM it! Introduction to BEMVarya Stepanova
 
Tối ưu-cau-lệnh-oracle-sql
Tối ưu-cau-lệnh-oracle-sqlTối ưu-cau-lệnh-oracle-sql
Tối ưu-cau-lệnh-oracle-sqlViet Tran
 
Introducción a HTML y CSS
Introducción a HTML y CSSIntroducción a HTML y CSS
Introducción a HTML y CSSAdriana Tienda
 
BEM It! for Brandwatch
BEM It! for BrandwatchBEM It! for Brandwatch
BEM It! for BrandwatchMax Shirshin
 
レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)
レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)
レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)NTT DATA Technology & Innovation
 
InnoDBのすゝめ(仮)
InnoDBのすゝめ(仮)InnoDBのすゝめ(仮)
InnoDBのすゝめ(仮)Takanori Sejima
 
CSS For Backend Developers
CSS For Backend DevelopersCSS For Backend Developers
CSS For Backend Developers10Clouds
 
인프런 - 스타트업 인프랩 시작 사례
인프런 - 스타트업 인프랩 시작 사례인프런 - 스타트업 인프랩 시작 사례
인프런 - 스타트업 인프랩 시작 사례Hyung Lee
 
Introducción al desarrollo web frontend
Introducción al desarrollo web frontendIntroducción al desarrollo web frontend
Introducción al desarrollo web frontendMax Kraszewski
 
ビッグデータ処理データベースの全体像と使い分け
ビッグデータ処理データベースの全体像と使い分けビッグデータ処理データベースの全体像と使い分け
ビッグデータ処理データベースの全体像と使い分けRecruit Technologies
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
XXE、SSRF、安全でないデシリアライゼーション入門
XXE、SSRF、安全でないデシリアライゼーション入門XXE、SSRF、安全でないデシリアライゼーション入門
XXE、SSRF、安全でないデシリアライゼーション入門Hiroshi Tokumaru
 
Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)
Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)
Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)Nuzhat Memon
 
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...Jer Clarke
 
JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...
JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...
JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...Citus Data
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaEdureka!
 

What's hot (20)

Pgday bdr 천정대
Pgday bdr 천정대Pgday bdr 천정대
Pgday bdr 천정대
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
BEM it! Introduction to BEM
BEM it! Introduction to BEMBEM it! Introduction to BEM
BEM it! Introduction to BEM
 
Tối ưu-cau-lệnh-oracle-sql
Tối ưu-cau-lệnh-oracle-sqlTối ưu-cau-lệnh-oracle-sql
Tối ưu-cau-lệnh-oracle-sql
 
Introducción a HTML y CSS
Introducción a HTML y CSSIntroducción a HTML y CSS
Introducción a HTML y CSS
 
BEM It! for Brandwatch
BEM It! for BrandwatchBEM It! for Brandwatch
BEM It! for Brandwatch
 
レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)
レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)
レプリケーション遅延の監視について(第40回PostgreSQLアンカンファレンス@オンライン 発表資料)
 
InnoDBのすゝめ(仮)
InnoDBのすゝめ(仮)InnoDBのすゝめ(仮)
InnoDBのすゝめ(仮)
 
CSS For Backend Developers
CSS For Backend DevelopersCSS For Backend Developers
CSS For Backend Developers
 
인프런 - 스타트업 인프랩 시작 사례
인프런 - 스타트업 인프랩 시작 사례인프런 - 스타트업 인프랩 시작 사례
인프런 - 스타트업 인프랩 시작 사례
 
Introducción al desarrollo web frontend
Introducción al desarrollo web frontendIntroducción al desarrollo web frontend
Introducción al desarrollo web frontend
 
ビッグデータ処理データベースの全体像と使い分け
ビッグデータ処理データベースの全体像と使い分けビッグデータ処理データベースの全体像と使い分け
ビッグデータ処理データベースの全体像と使い分け
 
Web components
Web componentsWeb components
Web components
 
Formatting tags
Formatting tagsFormatting tags
Formatting tags
 
XXE、SSRF、安全でないデシリアライゼーション入門
XXE、SSRF、安全でないデシリアライゼーション入門XXE、SSRF、安全でないデシリアライゼーション入門
XXE、SSRF、安全でないデシリアライゼーション入門
 
Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)
Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)
Std 10 Computer Chapter 3 Handling Images in HTML (Part 1)
 
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
 
JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...
JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...
JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 201...
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | Edureka
 
why we need ext4
why we need ext4why we need ext4
why we need ext4
 

Similar to CSS Bloat!

Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScriptSencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScriptDavid Kaneda
 
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ..."Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...Vijay Rayapati
 
WordPress Front End Optimizations
WordPress Front End OptimizationsWordPress Front End Optimizations
WordPress Front End OptimizationsScott Taylor
 
Advanced android
Advanced androidAdvanced android
Advanced androiddonnfelker
 
Dr. Strangelove: or How I learned to love HTML, CSS, and Javascript
Dr. Strangelove: or How I learned to love HTML, CSS, and JavascriptDr. Strangelove: or How I learned to love HTML, CSS, and Javascript
Dr. Strangelove: or How I learned to love HTML, CSS, and JavascriptRobotDeathSquad
 
BDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZBDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZleondu
 
IE9 для разработчиков
IE9 для разработчиковIE9 для разработчиков
IE9 для разработчиковYuriy Artyukh
 
In depth with html5 java2days 2010
In depth with html5 java2days 2010In depth with html5 java2days 2010
In depth with html5 java2days 2010Mystic Coders, LLC
 
Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010Zi Bin Cheah
 
Introducing Django-Servee
Introducing Django-ServeeIntroducing Django-Servee
Introducing Django-Serveeissackelly
 
From Singapore to Slovenia
From Singapore to SloveniaFrom Singapore to Slovenia
From Singapore to SloveniaSayanee Basu
 
Snowflake in music
Snowflake in musicSnowflake in music
Snowflake in musicErik Duval
 
Building Distributed JavaScript Widgets with jQuery
Building Distributed JavaScript Widgets with jQueryBuilding Distributed JavaScript Widgets with jQuery
Building Distributed JavaScript Widgets with jQuerybenvinegar
 
Progressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancementProgressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancementPaul Irish
 
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)
Persistence  Smoothie: Blending SQL and NoSQL (RubyNation Edition)Persistence  Smoothie: Blending SQL and NoSQL (RubyNation Edition)
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)Michael Bleigh
 
OvertheAir 2010 html5 impact on application programming
OvertheAir 2010 html5 impact on application programmingOvertheAir 2010 html5 impact on application programming
OvertheAir 2010 html5 impact on application programmingTor Björn Minde
 
HTML5 impact on application programming
HTML5 impact on application programmingHTML5 impact on application programming
HTML5 impact on application programmingEricsson Labs
 
Pony Pwning Djangocon 2010
Pony Pwning Djangocon 2010Pony Pwning Djangocon 2010
Pony Pwning Djangocon 2010Adam Baldwin
 
DjangoCon 2009 Keynote
DjangoCon 2009 KeynoteDjangoCon 2009 Keynote
DjangoCon 2009 KeynoteTed Leung
 
"Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ...
"Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ..."Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ...
"Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ...Christian Long
 

Similar to CSS Bloat! (20)

Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScriptSencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
Sencha Touch beta — Amazing Mobile Web Apps with HTML5, CSS3 & JavaScript
 
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ..."Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
 
WordPress Front End Optimizations
WordPress Front End OptimizationsWordPress Front End Optimizations
WordPress Front End Optimizations
 
Advanced android
Advanced androidAdvanced android
Advanced android
 
Dr. Strangelove: or How I learned to love HTML, CSS, and Javascript
Dr. Strangelove: or How I learned to love HTML, CSS, and JavascriptDr. Strangelove: or How I learned to love HTML, CSS, and Javascript
Dr. Strangelove: or How I learned to love HTML, CSS, and Javascript
 
BDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZBDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZ
 
IE9 для разработчиков
IE9 для разработчиковIE9 для разработчиков
IE9 для разработчиков
 
In depth with html5 java2days 2010
In depth with html5 java2days 2010In depth with html5 java2days 2010
In depth with html5 java2days 2010
 
Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010
 
Introducing Django-Servee
Introducing Django-ServeeIntroducing Django-Servee
Introducing Django-Servee
 
From Singapore to Slovenia
From Singapore to SloveniaFrom Singapore to Slovenia
From Singapore to Slovenia
 
Snowflake in music
Snowflake in musicSnowflake in music
Snowflake in music
 
Building Distributed JavaScript Widgets with jQuery
Building Distributed JavaScript Widgets with jQueryBuilding Distributed JavaScript Widgets with jQuery
Building Distributed JavaScript Widgets with jQuery
 
Progressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancementProgressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancement
 
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)
Persistence  Smoothie: Blending SQL and NoSQL (RubyNation Edition)Persistence  Smoothie: Blending SQL and NoSQL (RubyNation Edition)
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)
 
OvertheAir 2010 html5 impact on application programming
OvertheAir 2010 html5 impact on application programmingOvertheAir 2010 html5 impact on application programming
OvertheAir 2010 html5 impact on application programming
 
HTML5 impact on application programming
HTML5 impact on application programmingHTML5 impact on application programming
HTML5 impact on application programming
 
Pony Pwning Djangocon 2010
Pony Pwning Djangocon 2010Pony Pwning Djangocon 2010
Pony Pwning Djangocon 2010
 
DjangoCon 2009 Keynote
DjangoCon 2009 KeynoteDjangoCon 2009 Keynote
DjangoCon 2009 Keynote
 
"Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ...
"Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ..."Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ...
"Designing School 2.0 - Inspired by Agile Learners" - Christian Long keynote ...
 

More from Nicole Sullivan

Building the Media Block in ReactJS
Building the Media Block in ReactJS Building the Media Block in ReactJS
Building the Media Block in ReactJS Nicole Sullivan
 
Creating Living Style Guides to Improve Performance
Creating Living Style Guides to Improve PerformanceCreating Living Style Guides to Improve Performance
Creating Living Style Guides to Improve PerformanceNicole Sullivan
 
Our Best Practices Are Killing Us
Our Best Practices Are Killing UsOur Best Practices Are Killing Us
Our Best Practices Are Killing UsNicole Sullivan
 
5 Mistakes of Massive CSS
5 Mistakes of Massive CSS5 Mistakes of Massive CSS
5 Mistakes of Massive CSSNicole Sullivan
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...Nicole Sullivan
 
The Fast And The Fabulous
The Fast And The FabulousThe Fast And The Fabulous
The Fast And The FabulousNicole Sullivan
 
Pourquoi la performance?
Pourquoi la performance?Pourquoi la performance?
Pourquoi la performance?Nicole Sullivan
 
7 Habits of Exceptional Performance
7 Habits of Exceptional Performance7 Habits of Exceptional Performance
7 Habits of Exceptional PerformanceNicole Sullivan
 

More from Nicole Sullivan (15)

Building the Media Block in ReactJS
Building the Media Block in ReactJS Building the Media Block in ReactJS
Building the Media Block in ReactJS
 
Why are you here?
Why are you here?Why are you here?
Why are you here?
 
Creating Living Style Guides to Improve Performance
Creating Living Style Guides to Improve PerformanceCreating Living Style Guides to Improve Performance
Creating Living Style Guides to Improve Performance
 
Don't feed the trolls
Don't feed the trollsDon't feed the trolls
Don't feed the trolls
 
CSS Power Tools
CSS Power ToolsCSS Power Tools
CSS Power Tools
 
Our Best Practices Are Killing Us
Our Best Practices Are Killing UsOur Best Practices Are Killing Us
Our Best Practices Are Killing Us
 
5 Mistakes of Massive CSS
5 Mistakes of Massive CSS5 Mistakes of Massive CSS
5 Mistakes of Massive CSS
 
CSS Wish List @JSConf
CSS Wish List @JSConfCSS Wish List @JSConf
CSS Wish List @JSConf
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
 
Taming CSS Selectors
Taming CSS SelectorsTaming CSS Selectors
Taming CSS Selectors
 
The Fast And The Fabulous
The Fast And The FabulousThe Fast And The Fabulous
The Fast And The Fabulous
 
Pourquoi la performance?
Pourquoi la performance?Pourquoi la performance?
Pourquoi la performance?
 
Design Fast Websites
Design Fast WebsitesDesign Fast Websites
Design Fast Websites
 
7 Habits of Exceptional Performance
7 Habits of Exceptional Performance7 Habits of Exceptional Performance
7 Habits of Exceptional Performance
 
After YSlow "A"
After YSlow "A"After YSlow "A"
After YSlow "A"
 

CSS Bloat!

  • 1. CSS BLOAT! with Nicole Sullivan Friday, September 10, 2010
  • 2. TWEET! @stubbornella Friday, September 10, 2010
  • 3. WHY OPTIMIZE CSS? • It blocks progressive rendering test: http://www.phpied.com/files/css-loading/table.php • It’s verbose (property value pairs cannot be minified like JS) text-decoration: underline != td: u Friday, September 10, 2010
  • 4. TOP 1000 STUDY 1. Grab top Alexa sites 2. Start Fiddler 3. Load each site 4. Export from Fiddler Friday, September 10, 2010
  • 5. <?php $file = file('alexa.txt'); foreach ($file as $url) { launch($url); } function launch($url) { try { $ie = new COM("InternetExplorer.Application"); $ie->Visible = true; $ie->Navigate2($url); while ($ie->ReadyState != 4) sleep(1); $ie->Quit(); } catch (Exception $e) {} } ?> Friday, September 10, 2010
  • 6. 42% DON’T GZIP CSS Friday, September 10, 2010
  • 7. 44% HAVE MORE THAN 2 CSS FILES 56% 44% Friday, September 10, 2010
  • 8. 56% SERVE CSS WITH COOKIES Friday, September 10, 2010
  • 9. 62% DON’T MINIFY would get more than 10% savings from YUI compressor Friday, September 10, 2010
  • 10. 21% HAVE >100K OF CSS 21% 11% 11% 44% 24% Friday, September 10, 2010
  • 11. HASTE TRACE-BASED PACKAGING homepage homepage Date CSS files CSS weight files weight Nov 2008 487 1.7MB 24 69KB May 2009 706 1.9MB 15 64KB http://velocityconference.blip.tv/file/2293221/ David Wei & Changhao Jiang Friday, September 10, 2010
  • 12. KUDZU Was introduced to the United States between 1935 and 1950 by the Soil Conservation Service to prevent soil erosion. Friday, September 10, 2010
  • 14. “OBJECT ORIENTED CSS SOUNDS GREAT, BUT WE HAVE A GIANT MESS!” how do we get from here to there? Friday, September 10, 2010
  • 15. FACEBOOK DECIDED TO GO ON A DIET The CSS was one piece of the puzzle Friday, September 10, 2010
  • 16. Jason Sobel - Perf Manager Fu MANY PIECES Nan Gao Kyle Delong - PHP David Wei & Changhao Jiang BigPipe Marcel Laverdet - Tom Occhino - JS XHP Makinde Shaun McIntyre - Adeagbo - JS Automated Spriting Friday, September 10, 2010
  • 17. THEY REDUCED THEIR RESPONSE TIME BY HALF in only six months Friday, September 10, 2010
  • 18. WHAT IS OBJECT ORIENTED CSS? A philosophy? A framework? A tool? Friday, September 10, 2010
  • 19. MORE LIKE AN EVOLUTION OF THE LANGUAGE it makes CSS more powerful Friday, September 10, 2010
  • 20. HOW IS IT DIFFERENT? ul{...} ul li{...} ul li a{...} Friday, September 10, 2010
  • 21. HOW IS IT DIFFERENT? ul{...} ul li{...} ul li a{...} Until now, we focused all our effort here Friday, September 10, 2010
  • 22. HOW IS IT DIFFERENT? ul{...} ul li{...} ul li a{...} But, the architecture lives here Friday, September 10, 2010
  • 23. MUCH LESS CODE easier to work with newbies Friday, September 10, 2010
  • 24. GRIDS • 574 bytes • 14 lines of code • Percentage widths adapt to different page sizes • Includes halfs, thirds, fourths, and fifths • No gutters • Infinite nesting and stacking Friday, September 10, 2010
  • 25. GRANULARITY FAIL + STALE RULES + UNPREDICTABILITY + DUPLICATION + SPECIFICITY WARS = MASSIVE CSS Friday, September 10, 2010
  • 26. 5 Text GRANULARITY FAIL the CSS objects shouldn’t match the PHP objects Friday, September 10, 2010
  • 32. WE WANT TO DO THE SAME THING WITH CSS Friday, September 10, 2010
  • 33. CREATE THE BUILDING BLOCKS Friday, September 10, 2010
  • 34. MOST SITES GET THE GRANULARITY WRONG and their architecture is set up to fail Friday, September 10, 2010
  • 35. HOW? FIRST, A VISUAL INVENTORY Friday, September 10, 2010
  • 36. TAKE A PHP OBJECT Friday, September 10, 2010
  • 37. BREAK IT DOWN Friday, September 10, 2010
  • 38. 7 SMALLER OBJECTS Friday, September 10, 2010
  • 40. HEADINGS Heading - 16px bold #3B5998 Heading - 16px normal #333333 Heading - 15px bold #3B5998 • 12px headings eliminated Heading - 15px normal #333333 Heading - 14px bold #3B5998 • Blue only for links Heading - 14px normal #333333 Heading - 13px bold #3B5998 • Bold for all titles Heading - 13px normal #333333 • Chad Little went through Heading - 11px bold #3B5998 the entire site eliminating Heading - 11px normal #333333 duplicates. Friday, September 10, 2010
  • 41. IT’S ALL ABOUT PATTERN MATCHING but you have to take a step back Friday, September 10, 2010
  • 42. PHP OBJECTS != CSS OBJECTS you will be tempted, beware! Friday, September 10, 2010
  • 43. 4 Text STALE RULES CSS gets crufty Friday, September 10, 2010
  • 44. STALE IS TWO THINGS ❖ Truly stale - rules that are no longer used on the site ❖ Rules used on subsequent PV or activated on user action Friday, September 10, 2010
  • 45. WHAT KIND DO YOU HAVE? Friday, September 10, 2010
  • 46. WHAT KIND DO YOU HAVE? ❖ Try dust-me selectors Friday, September 10, 2010
  • 47. WHAT KIND DO YOU HAVE? ❖ Try dust-me selectors ❖ Track them over time - ‣ changes are more important than an absolute number Friday, September 10, 2010
  • 48. 3 Text UNPREDICTABILITY Make each object predictable and location independent Friday, September 10, 2010
  • 51. A Heading should not become a Heading in another part of the page. Friday, September 10, 2010
  • 52. AVOID EXAMPLE #weatherModule h3{color:red;} #tabs h3{color:blue} ❖ Global color undefined for h3, so it will be ‣ unstyled in new modules, ‣ developers forced to write more CSS for the same style Friday, September 10, 2010
  • 53. HOW DO YOU TEST FOR UNPREDICTABLE CODE? #foo h3{...} #bar h3{...} #baz h3{...} grep h[1-6] Friday, September 10, 2010
  • 54. h1-h6 How many? You need site-wide headings Friday, September 10, 2010
  • 55. 511 declarations setting styles for h1-h6 56% >10 9% >100 Friday, September 10, 2010
  • 56. HEADINGS BEFORE 958 declarations h1-h6 Facebook Friday, September 10, 2010
  • 57. HEADINGS AFTER: 25 Chad Little - Facebook Friday, September 10, 2010
  • 58. 2 Text SPECIFICITY WARS lobbing specificity grenades over the cube wall Friday, September 10, 2010
  • 59. SPECIFICITY SCREWS UP THE CASCADE and the cascade kind of rocks, so how do we use the good parts? Friday, September 10, 2010
  • 61. .mod .hd{...} .ie .mod .hd{...} .weatherMod .hd {...} USE HACKS SPARINGLY And don’t let them change your specificity Friday, September 10, 2010
  • 62. .mod .hd{...} X .ie .mod .hd{...} .weatherMod .hd {...} USE HACKS SPARINGLY And don’t let them change your specificity .mod .hd{color: red; _zoom:1;} .weatherMod .hd{...} Friday, September 10, 2010
  • 63. #navigation{...} #header{...} AVOID STYLING IDS IDs impact specificity and can’t be reused IDs are for JS Friday, September 10, 2010
  • 64. X #navigation{...} #header{...} AVOID STYLING IDS IDs impact specificity and can’t be reused IDs are for JS Friday, September 10, 2010
  • 65. .nav {color: red !important;} AVOID !IMPORTANT except on leaf nodes Friday, September 10, 2010
  • 66. .nav {color: red !important;} X AVOID !IMPORTANT except on leaf nodes Friday, September 10, 2010
  • 67. !IMPORTANT 518 declarations using important 12% have greater than 50 Friday, September 10, 2010
  • 68. div.error{...} STYLE CLASSES rather than elements Friday, September 10, 2010
  • 69. X div.error{...} STYLE CLASSES rather than elements .error{ most of the code goes here } Friday, September 10, 2010
  • 70. X div.error{...} STYLE CLASSES rather than elements .error{ most of the code goes here } div.error{ } p.error{ exceptions only } em.error{ } Friday, September 10, 2010
  • 71. html body .myModule div .hd{...} .myModule2 .hd {...} GIVE RULES THE SAME STRENGTH Use cascade order to overwrite previous rules Friday, September 10, 2010
  • 72. X html body .myModule div .hd{...} .myModule2 .hd {...} GIVE RULES THE SAME STRENGTH Use cascade order to overwrite previous rules .myModule .hd{...} .myModule2 .hd{...} Friday, September 10, 2010
  • 73. 1 Text DUPLICATION CSS kudzu on steroids Friday, September 10, 2010
  • 74. GREP IS YOUR FRIEND look at the stylesheets globally rather than per page Friday, September 10, 2010
  • 75. margin too many? You need reset.css Friday, September 10, 2010
  • 76. 518 declarations reset margin to zero 64% > 10 14% > 100 Friday, September 10, 2010
  • 77. float too many? You need grids Friday, September 10, 2010
  • 78. 733 declarations floated elements 56% > 10 13% > 100 Friday, September 10, 2010
  • 79. font-size headings may be disguised in class names Friday, September 10, 2010
  • 80. FONT-SIZE 889 declarations changed the font-size 78% >10 23% >100 Friday, September 10, 2010
  • 81. HOW DID FACEBOOK REDUCE DUPLICATION? let’s look at an example Friday, September 10, 2010
  • 82. MEDIA BLOCK EXAMPLE Friday, September 10, 2010
  • 83. ALL OF THESE ARE THE SAME OBJECT Friday, September 10, 2010
  • 84. WHAT DO WE KNOW? ❖ Can be nested ❖ Optional right button ❖ Must clearfix Friday, September 10, 2010
  • 85. WHAT DON’T WE KNOW? ❖ Image width and decoration vary ❖ Right content is unknown ❖ Width unknown Friday, September 10, 2010
  • 86. SEPARATE STRUCTURE FROM CHROME Friday, September 10, 2010
  • 87. A FEW LINES OF HTML... <div class="media attribution"> <a href="http://twitter.com/stubbornella" class="img"> <img src="mini.jpg" alt="Stubbornella" /> </a> <div class="bd">@Stubbornella 14 minutes ago</div> </div> Friday, September 10, 2010
  • 88. 4 LINES OF CSS... _ Friday, September 10, 2010
  • 90. HTML SIZE reduced by 50% by Stefan Parker Friday, September 10, 2010
  • 91. “Due to these efforts, we cut our average CSS bytes per page by 19% (after gzip) and HTML bytes per page by 44% (before gzip).” Jason Sobel http://www.facebook.com/note.php?note_id=307069903919 Friday, September 10, 2010
  • 92. LET’S KEEP TALKING... www.stubbornella.org @stubbornella OOCSS Project: http://github.com/stubbornella/oocss/ Friday, September 10, 2010