SlideShare a Scribd company logo
Optimización
CSS y JavaScript


                    @lucascepeda
            WebcatBCN, 14/03/2012
Optimizaciones muy distintas



    ● CSS: Optimización para el desarrollador*

    ● JavaScript: Optimización para el usuario*




@lucascepeda                          WebcatBCN, 14/03/2012
CSS: Lo que ya debes saber



    ●     Código inline, caca
    ●     @import, caca
    ●     Debe ir en el <head>
    ●     Usar shorthand




@lucascepeda                     WebcatBCN, 14/03/2012
CSS: Lo que ya tendrías que hacer



    ● Combinar
    ● Minimizar
    ● Comprimir




@lucascepeda                  WebcatBCN, 14/03/2012
CSS: Combinar


    <head>
        <link   rel="stylesheet"   type="text/css"   href="styles/yellow.css">
        <link   rel="stylesheet"   type="text/css"   href="styles/blue.css">
        <link   rel="stylesheet"   type="text/css"   href="styles/big.css">
        <link   rel="stylesheet"   type="text/css"   href="styles/bold.css">
    </head>




@lucascepeda                                                  WebcatBCN, 14/03/2012
CSS: Combinar


    <head>
        <link rel="stylesheet" type="text/css" href="styles/combined.css">
    </head>




@lucascepeda                                            WebcatBCN, 14/03/2012
CSS: Minimizar


    /*****
      Multi-line comment
      before a new class name
    *****/
    .classname {
        /* comment in declaration block */
        font-weight: normal;
    }




@lucascepeda                                 WebcatBCN, 14/03/2012
CSS: Minimizar


    .classname{font-weight:normal}




@lucascepeda                         WebcatBCN, 14/03/2012
CSS: Combinar y minimizar



    YUI Compressor: http://developer.yahoo.com/yui/compressor/
    minify: http://code.google.com/p/minify/




@lucascepeda                                     WebcatBCN, 14/03/2012
CSS: Comprimir



    En servidor (apache, node.js, lighttp, IIS...)
      ● gzip
      ● zlib




@lucascepeda                              WebcatBCN, 14/03/2012
CSS: Lo que quizá no sepas



    ● 25K
    ● RTL
    #footer .column ul li a { color: #FAFAFA }



    ● CSS antes que JS en el <head>



@lucascepeda                                     WebcatBCN, 14/03/2012
CSS: CSS antes que JS en <head>




@lucascepeda                WebcatBCN, 14/03/2012
CSS: CSS antes que JS en <head>




@lucascepeda                WebcatBCN, 14/03/2012
CSS: Best practices



    ● IDs vs Clases
    ● Selectores eficientes
    ● OOCSS




@lucascepeda                  WebcatBCN, 14/03/2012
CSS: Optimización prematura




@lucascepeda                 WebcatBCN, 14/03/2012
CSS: Optimización prematura




@lucascepeda                 WebcatBCN, 14/03/2012
CSS: Problemas conocidos



    ● :hover en elementos distintos que <a>
    ● border-radius en IE9
    ● Expresiones en IE




@lucascepeda                        WebcatBCN, 14/03/2012
JS: Lo que ya debes saber



    ● Bloques <script> al final
    ● Evitar document.write
    ● eval es evil




@lucascepeda                      WebcatBCN, 14/03/2012
JS: Lo que ya tendrías que hacer



    ● Combinar
    ● Minimizar
    ● Comprimir




@lucascepeda                  WebcatBCN, 14/03/2012
JS: Combinar




@lucascepeda       WebcatBCN, 14/03/2012
JS: Lo que quizá no sepas



    ● Smart Event Handler
    ● Mantener la estructura de los objetos
    ● Selectores




@lucascepeda                          WebcatBCN, 14/03/2012
JS: Smart Event Handlers




@lucascepeda                   WebcatBCN, 14/03/2012
JS: Mantener estructura en objetos


    var universe = {
       answer: 42
    };
    // do something else
    universe.panic = false;




@lucascepeda                  WebcatBCN, 14/03/2012
JS: Mantener estructura en objetos


    var universe = {
      answer: 42,
      panic: true
    };
    // do something else
    universe.panic = false;




@lucascepeda                  WebcatBCN, 14/03/2012
JS: Mantener estructura en objetos




 http://jsperf.com/javascript-object-structure-speed-matters/2




@lucascepeda                                                     WebcatBCN, 14/03/2012
JS: Selectores




 http://jsperf.com/id-vs-class-vs-tag-selectors/2




@lucascepeda                                        WebcatBCN, 14/03/2012
JS: Selectores (CSS3 not vs .not)




 http://jsperf.com/jquery-css3-not-vs-not




@lucascepeda                                WebcatBCN, 14/03/2012
JS: Selectores (nativo vs liberías)




 http://jsperf.com/finding-an-element-w-jquery/6




@lucascepeda                                       WebcatBCN, 14/03/2012
JS: Loops




 http://jsperf.com/loops/29


@lucascepeda                  WebcatBCN, 14/03/2012
JS: ??????

Array(2).concat(b, c)[String(a).match(/(t)|(f)/).join().split(',,').push(1)]




@lucascepeda                                           WebcatBCN, 14/03/2012
JS: ??????

Array(2).concat(b, c)[String(a).match(/(t)|(f)/).join().split(',,').push(1)]



[0, 1, 2, 3, b, c][String(a).length]




@lucascepeda                                           WebcatBCN, 14/03/2012
JS: ??????

Array(2).concat(b, c)[String(a).match(/(t)|(f)/).join().split(',,').push(1)]



[0, 1, 2, 3, b, c][String(a).length]



({
  'true': b,
  'false': c
})[a]




@lucascepeda                                           WebcatBCN, 14/03/2012
JS: ??????

Array(2).concat(b, c)[String(a).match(/(t)|(f)/).join().split(',,').push(1)]



[0, 1, 2, 3, b, c][String(a).length]



({
  'true': b,
  'false': c
})[a]



switch(a) {
  case true: return b
  case false: return c
}



@lucascepeda                                           WebcatBCN, 14/03/2012
JS: ternary operator vs alternatives




 http://jsperf.com/ternary-operators/3



@lucascepeda                             WebcatBCN, 14/03/2012
JS: localStorage vs cookies




 http://jsperf.com/localstorage-vs-objects/19



@lucascepeda                                    WebcatBCN, 14/03/2012
Referencias CSS


  http://speckyboy.com/2011/03/08/website-speed-part-1-write-more-efficient-css
  http://www.impressivewebs.com/css-specificity-irrelevant/
  http://code.google.com/speed/page-speed/docs/rendering.html
  http://www.stubbornella.org/content/2011/04/28/our-best-practices-are-killing-us/
  http://www.stevesouders.com/blog/2009/03/10/performance-impact-of-css-selectors




@lucascepeda                                                 WebcatBCN, 14/03/2012
Referencias JS


  http://code.google.com/speed/page-speed/docs/
  http://developer.yahoo.com/performance/
  http://ariya.ofilabs.com/2012/02/javascript-object-structure-speed-matters.html
  http://css-tricks.com/thinking-async/
  http://jsperf.com




@lucascepeda                                                    WebcatBCN, 14/03/2012
Gracias


                  @lucascepeda
          WebcatBCN, 14/03/2012
@lucascepeda   WebcatBCN, 14/03/2012

More Related Content

PPTX
NU Web Steering Committee - Oct 11 - Web Performance
PDF
Passing a Front end Developer interview
KEY
Web Performance - A Whistlestop Tour
PDF
Developing a Web Application
PPTX
HTTP 2.0 - Web Unleashed 2015
PDF
PrairieDevCon 2014 - Web Doesn't Mean Slow
PDF
Levent-Gurses' Introduction to Web Components & Polymer
PDF
Speed is Essential for a Great Web Experience (Digicure - Copenhagen)
NU Web Steering Committee - Oct 11 - Web Performance
Passing a Front end Developer interview
Web Performance - A Whistlestop Tour
Developing a Web Application
HTTP 2.0 - Web Unleashed 2015
PrairieDevCon 2014 - Web Doesn't Mean Slow
Levent-Gurses' Introduction to Web Components & Polymer
Speed is Essential for a Great Web Experience (Digicure - Copenhagen)

What's hot (18)

ODP
Moving from Web 1.0 to Web 2.0
PPTX
EdTechJoker Spring 2020 - Lecture 4 - HTML
PDF
Real World Web components
PDF
Build Better Responsive websites. Hrvoje Jurišić
PPTX
Web application using JSP
PDF
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
PDF
State of jQuery '09
PDF
Web Fundamentals Crash Course
PDF
Nuxtjs cheat-sheet
PPT
Please dont touch-3.6-jsday
PPT
Going Mobile
PDF
Overview on jQuery mobile
PPTX
Introduction to jquery mobile with Phonegap
PDF
Necc 2008 Annotations
PPTX
Harness jQuery Templates and Data Link
PDF
jQueryTO: State of jQuery March 2013
PDF
What is jQuery?
PDF
Hacking MediaWiki (For Users)
Moving from Web 1.0 to Web 2.0
EdTechJoker Spring 2020 - Lecture 4 - HTML
Real World Web components
Build Better Responsive websites. Hrvoje Jurišić
Web application using JSP
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
State of jQuery '09
Web Fundamentals Crash Course
Nuxtjs cheat-sheet
Please dont touch-3.6-jsday
Going Mobile
Overview on jQuery mobile
Introduction to jquery mobile with Phonegap
Necc 2008 Annotations
Harness jQuery Templates and Data Link
jQueryTO: State of jQuery March 2013
What is jQuery?
Hacking MediaWiki (For Users)
Ad

Similar to Optimización JavaScript y CSS (20)

PDF
LESS, the CSS Preprocessor
PDF
DrupalCampLA 2011 - Drupal frontend-optimizing
KEY
Faster Frontends
PDF
Our application got popular and now it breaks
PDF
Our application got popular and now it breaks
PPT
Testable client side_mvc_apps_in_javascript
PDF
EnterJS 2015 - Continuous Integration for Frontend Code
PDF
SMX_DevTools_Monaco_2.pdf
PPTX
Angular + Components
PPTX
Liking performance
PDF
Using LESS, the CSS Preprocessor: J and Beyond 2013
PDF
Using RequireJS with CakePHP
PPTX
Introduction to Web Technologies PPT.pptx
PDF
Frontend Performance: Illusions & browser rendering
PDF
BEM Methodology — @Frontenders Ticino —17/09/2014
PDF
Web Projects: From Theory To Practice
PPTX
JavaScript Perfomance
PPTX
JavaScript Performance (at SFJS)
PDF
Struts 2 Design and Programming A Tutorial 2nd Edition Budi Kurniawan
PPT
SiteMesh
LESS, the CSS Preprocessor
DrupalCampLA 2011 - Drupal frontend-optimizing
Faster Frontends
Our application got popular and now it breaks
Our application got popular and now it breaks
Testable client side_mvc_apps_in_javascript
EnterJS 2015 - Continuous Integration for Frontend Code
SMX_DevTools_Monaco_2.pdf
Angular + Components
Liking performance
Using LESS, the CSS Preprocessor: J and Beyond 2013
Using RequireJS with CakePHP
Introduction to Web Technologies PPT.pptx
Frontend Performance: Illusions & browser rendering
BEM Methodology — @Frontenders Ticino —17/09/2014
Web Projects: From Theory To Practice
JavaScript Perfomance
JavaScript Performance (at SFJS)
Struts 2 Design and Programming A Tutorial 2nd Edition Budi Kurniawan
SiteMesh
Ad

Recently uploaded (20)

PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PPTX
Evolution_of_Computing_Presentation (1).pptx
PPT
robotS AND ROBOTICSOF HUMANS AND MACHINES
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PPTX
Entrepreneur intro, origin, process, method
PDF
Urban Design Final Project-Context
PDF
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
PPTX
CLASSIFICATION OF YARN- process, explanation
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PPTX
22CDH01-V3-UNIT III-UX-UI for Immersive Design
PPTX
22CDH01-V3-UNIT-I INTRODUCITON TO EXTENDED REALITY
PDF
2025_AIFG_Akane_Kikuchi_Empathy_Design.PDF
PPT
EthicsNotesSTUDENTCOPYfghhnmncssssx sjsjsj
PDF
321 LIBRARY DESIGN.pdf43354445t6556t5656
PPTX
EDP Competencies-types, process, explanation
PPTX
NEW EIA PART B - Group 5 (Section 50).pptx
PPTX
22CDO02-IMGD-UNIT-I-MOBILE GAME DESIGN PROCESS
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PPTX
Media And Information Literacy for Grade 12
PPT
aksharma-dfs.pptgfgfgdfgdgdfgdfgdgdrgdgdgdgdgdgadgdgd
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
Evolution_of_Computing_Presentation (1).pptx
robotS AND ROBOTICSOF HUMANS AND MACHINES
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
Entrepreneur intro, origin, process, method
Urban Design Final Project-Context
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
CLASSIFICATION OF YARN- process, explanation
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
22CDH01-V3-UNIT III-UX-UI for Immersive Design
22CDH01-V3-UNIT-I INTRODUCITON TO EXTENDED REALITY
2025_AIFG_Akane_Kikuchi_Empathy_Design.PDF
EthicsNotesSTUDENTCOPYfghhnmncssssx sjsjsj
321 LIBRARY DESIGN.pdf43354445t6556t5656
EDP Competencies-types, process, explanation
NEW EIA PART B - Group 5 (Section 50).pptx
22CDO02-IMGD-UNIT-I-MOBILE GAME DESIGN PROCESS
DOC-20250430-WA0014._20250714_235747_0000.pptx
Media And Information Literacy for Grade 12
aksharma-dfs.pptgfgfgdfgdgdfgdfgdgdrgdgdgdgdgdgadgdgd

Optimización JavaScript y CSS