Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

The Performance and Usability of Font Loading (...

The Performance and Usability of Font Loading (Velocity Santa Clara 2015)

A deep dive into @font-face for Velocity 2015 in Santa Clara.

http://velocityconf.com/devops-web-performance-2015/public/schedule/detail/41593

zachleat

May 28, 2015
Tweet

More Decks by zachleat

Other Decks in Programming

Transcript

  1. THE DEFAULT BROWSER BEHAVIOR FOR FONT-LOADING IS HARMFUL TO BOTH

    THE PERCEIVED PERFORMANCE AND INTEGRITY OF CONTENT ON THE WEB.
  2. THE DEFAULT BROWSER BEHAVIOR FOR FONT-LOADING IS HARMFUL TO BOTH

    THE PERCEIVED PERFORMANCE AND INTEGRITY OF CONTENT ON THE WEB. FONT-LOADING INTEGRITY PERCEIVED PERFORMANCE
  3. IMG

  4. IMG

  5. CSS

  6. A G EN D A TRIGGER A FONT DOWNLOAD BEHAVIOR

    WHILE DOWNLOADING 1.   2.  
  7. @font-­‐face  {    font-­‐family:  The  Font  that  Could;    src:

     url('icanfont.woff2')            format('woff2'),          url('icanfont.woff')            format('woff'),          url('icanfont.otf')            format('opentype');   }
  8. IS 30% SMALLER THAN WOFF On average across all of

    Google Fonts: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/j27Ou4RtvQI/discussion WOFF2
  9. <!doctype  html>   <style>   @font-­‐face  {    font-­‐family:  My

     Web  Font;    src:  url('icanfont.woff2')  format('woff2'),        url('icanfont.woff')  format('woff'),        url('icanfont.otf')  format('opentype');   }   </style>  
  10. 8 36–42 23–28 6.1–8 2.3, 4.1 7–8 DOWNLOADS WITH EMPTY

    ATTACHED ELEMENT DOWNLOADS EVERY TIME DOWNLOADS WITH NON-EMPTY ATTACHED ELEMENT 28–37 9–11
  11. 8 36–42 23–28 6.1–8 2.3, 4.1 7–8 DOWNLOADS WITH EMPTY

    ATTACHED ELEMENT DOWNLOADS EVERY TIME DOWNLOADS WITH NON-EMPTY ATTACHED ELEMENT 28–37 9–11
  12. BASIC LATIN CODE POINTS Arial Chunk Five x26 & &

    x41 A A x42 B B x43 C C x2B + + x3F ? ?
  13. @font-­‐face  {     font-­‐family:  Ampersand;     src:  url('sands.woff2')

     format('woff2'),                url('sands.woff')  format('woff'),                url('sands.ttf')  format('truetype');      unicode-­‐range:  U+26;   } unicode- range
  14. unicode- range 36 9, 10, 11 23 8 4.1 8

    ALWAYS DOWNLOADS SMART DOWNLOAD NOT SUPPORTED
  15. unicode- range 36 9, 10, 11 23 8 4.1 8

    ALWAYS DOWNLOADS SMART DOWNLOAD NOT SUPPORTED
  16. <!doctype  html>   <style>   @font-­‐face  {    font-­‐family:  My

     Web  Font;    src:  url('icanfont.woff2')  format('woff2'),        url('icanfont.woff')  format('woff'),        url('icanfont.otf')  format('opentype');      font-­‐weight:  400;      font-­‐style:  normal;   }   </style>  
  17. <style>   p  {      font-­‐family:  My  Web  Font;

         font-­‐weight:  400;      font-­‐style:  normal;   }   </style>   <p>Roman  Text</p>
  18. @font-­‐face  {      font-­‐family:  My  Web  Font;    

     font-­‐weight:  400;      font-­‐style:  normal;   } p  {      font-­‐family:  My  Web  Font;      font-­‐weight:  400;      font-­‐style:  normal;   }
  19. @font-­‐face  {      font-­‐family:  My  Web  Font;    

     font-­‐weight:  400;      font-­‐style:  normal;   } p  {      font-­‐family:  My  Web  Font;      font-­‐weight:  400;      font-­‐style:  normal;   } ✔
  20. 100  200  300  400  500  600  700  800  900 FONT-WEIGHT

    DEFAULT  CSS   font-­‐weight:  normal; DEFAULT  CSS   font-­‐weight:  bold; ‐ ‑ ‑ ‐ Lighter  weights Bolder  weights
  21. @font-­‐face  {  font-­‐weight:  500;  font-­‐style:  normal;  }   @font-­‐face  {

     font-­‐weight:  400;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  300;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  200;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  100;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  600;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  700;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  800;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  900;  font-­‐style:  normal;  }   /*  REPEAT  THE  SAME,  WITH  font-­‐style:  italic;  */ p  {      font-­‐weight:  500;      font-­‐style:  normal;   }
  22. 100  200  300  400  500  600  700  800  900 FONT-WEIGHT

    <p> ‐ ‑ ‐ Lighter  weights Bolder  weights
  23. MisMatch weight 600 Available, 100 assigned, FORCED BOLD p  {

         font-­‐family:  My  Web  Font;      font-­‐weight:  100;      font-­‐style:  normal;   } @font-­‐face  {      font-­‐family:  My  Web  Font;      font-­‐weight:  600;      font-­‐style:  normal;   }
  24. MISMATCH STYLE ITALIC AVAILABLE, NORMAL ASSIGNED, FORCED ITALIC p  {

         font-­‐family:  My  Web  Font;      font-­‐weight:  400;      font-­‐style:  normal;   } @font-­‐face  {      font-­‐family:  My  Web  Font;      font-­‐weight:  400;      font-­‐style:  italic;   }
  25. @font-­‐face  {  font-­‐weight:  600;  font-­‐style:  normal;  }   @font-­‐face  {

     font-­‐weight:  700;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  800;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  900;  font-­‐style:  normal;  }   /*  FAUX  BOLD  */   @font-­‐face  {  font-­‐weight:  500;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  400;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  300;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  200;  font-­‐style:  normal;  }   @font-­‐face  {  font-­‐weight:  100;  font-­‐style:  normal;  }   /*  END  FAUX  BOLD  */   /*  REPEAT  THE  SAME,  WITH  font-­‐style:  italic;  */ p  {      font-­‐weight:  600;      font-­‐style:  normal;   }
  26. 100  200  300  400  500  600  700  800  900 FONT-WEIGHT

    <p> ‐ ‑ ‐ Normal/Roman  @font-­‐face Bold  @font-­‐face Faux  Bold
  27. MisMatch weight 500 Available, 600 assigned, FAUX BOLD p  {

         font-­‐family:  My  Web  Font;      font-­‐weight:  600;      font-­‐style:  normal;   } @font-­‐face  {      font-­‐family:  My  Web  Font;      font-­‐weight:  500;      font-­‐style:  normal;   }
  28. MISMATCH STYLE p  {      font-­‐family:  My  Web  Font;

         font-­‐weight:  400;      font-­‐style:  italic;   } @font-­‐face  {      font-­‐family:  My  Web  Font;      font-­‐weight:  400;      font-­‐style:  normal;   } NORMAL AVAILABLE, ITALIC ASSIGNED, FAUX ITALIC
  29. <style>   @font-­‐face  {      font-­‐weight:  400;    

     font-­‐style:  normal;   }   </style>   <p>      Roman  Text      <strong>Bold  Text</strong>      <b>Bold  Text</b>      <em>Italic  Text</em>      <i>Italic  Text</i>   </p>
  30. <i>

  31. i,  cite,  em,  var,   address,  dfn,   strong,  b,

     h1,  h2,   h3,  h4,  h5,  h6,  th
  32. A G EN D A TRIGGER A FONT DOWNLOAD BEHAVIOR

    WHILE DOWNLOADING 1.   2.  
  33. A G EN D A TRIGGER A FONT DOWNLOAD BEHAVIOR

    WHILE DOWNLOADING 1.   2.  
  34. People will visit a Web site less often if it

    is slower than a close competitor by more than 250 milliseconds.” http://www.nytimes.com/2012/03/01/technology/impatient-web-users-flee-slow-loading-sites.html “
  35. FOUT DO NOTHING EMBRACE BROWSER DEFAULTS 0 SECOND TIMEOUT FOUT

    FOIT N SECOND TIMEOUT FOIT InFINITE TIMEOUT N  >  0
  36. FOUT DO NOTHING EMBRACE BROWSER DEFAULTS 0 SECOND TIMEOUT FOUT

    FOIT N SECOND TIMEOUT FOIT InFINITE TIMEOUT N  >  0
  37. FOUT DO NOTHING EMBRACE BROWSER DEFAULTS 0 SECOND TIMEOUT FOUT

    FOIT N SECOND TIMEOUT FOIT InFINITE TIMEOUT N  >  0
  38. <style>   h1  {  font-­‐family:  serif;  }   .loaded  h1

     {  font-­‐family:  My  Web  Font;  }   </style>   <link  href="fonts.css"   onload="document.body.className+='   loaded';"  rel="stylesheet">  
  39. @font-­‐face  {      font-­‐family:  My  Web  Font;    

     src:  url('icanfont.woff')  format('woff');   }   @font-­‐face  {      font-­‐family:  My  Web  Font;      src:  url('icanfontbold.woff')  format('woff');      font-­‐weight:  700;   }
  40. <style>   h1  {  font-­‐family:  serif;  }   .loaded  h1

     {  font-­‐family:  My  Web  Font;  }   </style>   <link  href="fonts.css"  media="none"   onload="document.body.className+='   loaded';  this.media='all'"   rel="stylesheet">  
  41. @font-­‐face  {      font-­‐family:  My  Web  Font;    

     src:  url('data:application/x-­‐font-­‐ woff;charset=utf-­‐8;base64,...')  format('woff');   }   @font-­‐face  {      font-­‐family:  My  Web  Font;      src:  url('data:application/x-­‐font-­‐ woff;charset=utf-­‐8;base64,...')  format('woff');      font-­‐weight:  700;   }
  42. ASYNC FONTS.CSS Font  Data  URIs   finish   loading B

    A Font  Data  URIs   start   loading REPAINT
  43. @font-­‐face  {      font-­‐family:  Roboto;      src:  url('data:application/x-­‐font-­‐

    woff;charset=utf-­‐8;base64,...')  format('woff');   }   @font-­‐face  {      font-­‐family:  Roboto;      src:  url('data:application/x-­‐font-­‐ woff;charset=utf-­‐8;base64,...')  format('woff');      font-­‐weight:  700;   }
  44. FONTFACEONLOAD github.com/zachleat/fontfaceonload USES THE CSS FONT LOADING API WHEN AVAILABLE.

    FONTFACEOBSERVER github.com/bramstein/fontfaceobserver/ INCLUDES A NICE PROMISES POLYFILL
  45. var  doc  =  document,          docEl  =

     doc.documentElement;   doc.fonts.load("1em  Raleway")    .then(function()  {          //  The  font  has  loaded.      docEl.className  +=  "  raleway-­‐loaded";    }); ‑
  46. body  {      font-­‐family:  sans-­‐serif;   }   .raleway-­‐loaded

     body  {      font-­‐family:  Raleway,  sans-­‐serif;   } ‑
  47. var  docEl  =  document.documentElement;   docEl.className  +=  "  raleway-­‐loading";  

    window.setTimeout(function()  {      docEl.className  +=  "  raleway-­‐fallback";   },  1000);   document.fonts.load("1em  Raleway").then(function()  {      docEl.className  +=  "  raleway-­‐loaded";   });   ‑
  48. .raleway-­‐loading  body  {      color:  transparent;   }  

    .raleway-­‐fallback  body,   .raleway-­‐loaded  body  {      color:  inherit;   }   .raleway-­‐fallback  body  {      font-­‐family:  serif;   }   .raleway-­‐loaded  body  {      font-­‐family:  Raleway,  serif;   } ‑
  49. Promise.all([      document.fonts.load("400  1em  Raleway"),      document.fonts.load("700  1em

     Raleway")   ]).then(function  ()  {      docEl.className  +=  "  raleway-­‐loaded";   }); ‑ document.fonts.load("1em  Raleway").then(function()  {      docEl.className  +=  "  raleway-­‐loaded";   }); BECOMES
  50. THERE ARE A LOT OF TOOLS AT OUR DISPOSAL TO

    EASE THE TRANSITION FROM FALLBACK TO WEBFONT
  51. THE DEFAULT BROWSER BEHAVIOR FOR FONT-LOADING IS HARMFUL TO BOTH

    THE PERCEIVED PERFORMANCE AND INTEGRITY OF CONTENT ON THE WEB.
  52. THE DEFAULT BROWSER BEHAVIOR FOR FONT-LOADING IS HARMFUL TO BOTH

    THE PERCEIVED PERFORMANCE AND INTEGRITY OF CONTENT ON THE WEB. FONT-LOADING INTEGRITY PERCEIVED PERFORMANCE