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

Optimize or Die Tryin'

Optimize or Die Tryin'

This talk was made at Blend Conference (Lyon, October 1st and 2nd 2013).
It covers a simple process to optimize your page loading.

Damian Le Nouaille

October 01, 2013
Tweet

More Decks by Damian Le Nouaille

Other Decks in Programming

Transcript

  1. Optimize
    or
    Die Tryin’
    Damian Le Nouaille
    CTO at Geeksters, Prof’ IngéSup, HashtagBattle
    @damln

    View full-size slide

  2. Today
    BACKEND
    FRONTEND
    Today it’s me!

    View full-size slide

  3. FLAT DESIGN
    =
    PERFORMANCE

    View full-size slide

  4. Frustration: Indirect Performance
    ● Not visible in development
    ● Fast computers
    ● Very fast Internet access
    ● localhost
    Oh it’s fast! Look at my computer.
    PS: You’re not the end user.

    View full-size slide

  5. Timeline
    HTML
    What we
    want !
    JavaScript
    Images
    DOMReady

    CSS

    View full-size slide

  6. Plan
    ● Images
    ● Concatenation
    ● Minification
    ● Compression
    ● Versionning
    ● Async
    ● Share Buttons
    ● Extra

    View full-size slide

  7. Images: format, size and optimisazion
    ● Choose the format: PNG 8-24 bits? JPEG?
    ● Right size: 800x600 for a thumbnail?
    ● Paint: width + height on
    ● ImageOptim, remove meta-data, reduce
    image weight
    ● No images: Fonts or SVG (for icons)

    View full-size slide

  8. Images: Example

    View full-size slide

  9. Reminder ...

    View full-size slide

  10. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  11. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    Goal

    View full-size slide

  12. Concatenation
    Goal:
    ● Reduce number of requests
    Tools:
    ● Sass : use partials for CSS
    ● Grunt (grunt-contrib-concat) :
    Combine JavaScript files in the right order

    View full-size slide

  13. Concatenation: Example
    _global.scss
    main.css
    _nav.scss
    _sidebar.scss
    160 Ko 111 Ko

    View full-size slide

  14. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  15. Timeline: After Concatenation
    HTML CSS JavaScript
    Images
    DOMReady

    Goal

    View full-size slide

  16. Minification
    Goal:
    ● Reduce the weight of the request
    Tools:
    ● Sass : ouputFormat :compressed
    ● Grunt : grunt-contrib-uglify

    View full-size slide

  17. Thanks, Brackets <3
    ● Browsers don’t care about formating
    ● Thanks!
    {;}

    View full-size slide

  18. Minification: Example
    111 Ko 88 Ko

    View full-size slide

  19. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  20. Timeline: After Minification
    HTML CSS JavaScript
    Images
    DOMReady

    Goal

    View full-size slide

  21. Compression (Gzip)
    Goal:
    ● Reduce the weight of the request,
    even MORE
    Why:
    ● It’s easy to compress text
    ● Good support (IE8+)

    View full-size slide

  22. Compression: Example
    88 Ko 16 Ko

    View full-size slide

  23. Compression: Real
    Accept-Encoding:gzip,deflate,
    sdch
    /css/main.css
    main.css
    main.css.gz
    GZIP
    Content-Encoding:gzip
    GZIP content
    NGINX / APACHE

    View full-size slide

  24. Compression: Check Weight

    View full-size slide

  25. Compression: Check Headers

    View full-size slide

  26. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  27. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    Goal

    View full-size slide

  28. Versionning: Cache Busting
    Goal:
    ● Don’t GET existing assets
    Basics:
    ● Rename assets (with MD5)
    ● HTTP header : max-age=30000000

    View full-size slide

  29. “It works for me”
    ● “Hi Bob, I upload the latest modifications.”
    ● “I don’t see them, I have an old version.”
    ● “Aaahhhhrrrrgffgg”
    Bob’s iPad is crap.
    NO!

    View full-size slide

  30. Versionning: Grunt-Hash
    lib.min.js MD5
    lib.min.12345678.js
    assets.json
    {
    “lib.min.js”: ”lib.min.12345678.js”,
    ...
    }

    View full-size slide

  31. Versionning: ViewHelper

    View full-size slide

  32. Grunt, is it fast?
    1.6 sec

    View full-size slide

  33. Async loading
    Goal:
    ● Accelerate the DOM Load
    ● Provide visual feedback to visitor
    Where:
    ● Images
    ● JavaScript

    View full-size slide

  34. Async load: Images
    How:
    ● Change the source: src=”load.gif”
    ● Add: data-src=”image.jpg”
    ● Use a plugin to replace src
    by data-src
    ● Unveil.js

    View full-size slide

  35. Images: Example
    HTML
    JavaScript

    View full-size slide

  36. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  37. Timeline: After Unveil.js
    HTML CSS JavaScript
    Images
    DOMReady

    Goal

    View full-size slide

  38. Async load: JavaScript
    How:
    ● Use head.js
    ● Declare the files
    ● Use the callback
    ● NO AMD
    ● DEAD SIMPLE

    View full-size slide

  39. JavaScript: Example

    View full-size slide

  40. Timeline
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  41. Timeline: After head.js
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  42. Timeline: After Cache
    HTML CSS JavaScript
    Images
    DOMReady

    View full-size slide

  43. Share Buttons
    ● Facebook likes, Tweet button, etc
    ● Useless for the rendering
    ● Trigger load at the right time
    Plugins:
    ● Socialite
    ● AddThis
    ● Sharrre

    View full-size slide

  44. Extra
    ● Sprite CSS : Compass
    ● CDN : Latency / Mobile
    ● Turbolinks : PJAX evolution
    Tools et readings :
    ● YSlow
    ● Page Speed Insights : Online + Chrome
    ● Guides : Yahoo et Google

    View full-size slide

  45. Recap’
    Source Concat Min Cache
    Hash Gzip Async
    160 Ko 111 Ko 88 Ko 88 Ko 16 Ko
    MD5
    Development Server Client

    View full-size slide

  46. Thanks
    Damian Le Nouaille
    www.damln.com
    www.geeksters.co
    Twitter, Github, Coderwall:
    @damln

    View full-size slide