fel presentation

28
Web Fonts vs Web Performance @ianfeather - Front End London, May 2013 Friday, 31 May 13

Upload: ianfeather

Post on 29-Nov-2014

1.580 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Fel presentation

Web Fonts vs Web Performance

@ianfeather - Front End London, May 2013

Friday, 31 May 13

Page 2: Fel presentation

Friday, 31 May 13

Page 3: Fel presentation

Friday, 31 May 13

Page 4: Fel presentation

Friday, 31 May 13

Page 5: Fel presentation

Friday, 31 May 13

Page 6: Fel presentation

Friday, 31 May 13

Page 7: Fel presentation

How Critical is Critical?

Friday, 31 May 13

Page 8: Fel presentation

Friday, 31 May 13

Page 9: Fel presentation

Friday, 31 May 13

Page 10: Fel presentation

Why are fonts critical?

• FOUT, what is it?

• Where did it come from?

• How big a deal is it?

Friday, 31 May 13

Page 11: Fel presentation

The Browser

• Leverage them!

• They do your work for you

• But... you don’t always have to agree with them

Friday, 31 May 13

Page 12: Fel presentation

“...user agents may render text as it would be rendered if downloadable font resources are not available or they may render text transparently with fallback fonts to avoid a flash of text using a fallback font.”

The Spec

In cases where the font download fails user agents must display text, simply leaving transparent text is considered non-conformant behavior.”

Friday, 31 May 13

Page 13: Fel presentation

The Implementation

IE FF Chrome, Safari, Opera (2.15)

Text rendered immediately then repainted later

Invisible Text

3s Timeout

Invisible Text

No Timeout

PS. They’re working on it...https://bugs.webkit.org/show_bug.cgi?id=25207 ~ 2009https://code.google.com/p/chromium/issues/detail?id=235303 ~ 2013

Friday, 31 May 13

Page 14: Fel presentation

What are our options?

Friday, 31 May 13

Page 15: Fel presentation

Font Serving Services

• JS Options e.g. Typekit

• Google Web Font Loaderhttp://www.slideshare.net/clagnut/responsive-web-fonts

• Self hosted

Friday, 31 May 13

Page 16: Fel presentation

What’s in a font?

TypeTool, Font Forge, Glyphs & Glyphs MiniFriday, 31 May 13

Page 17: Fel presentation

Subset your font

Don’t forget the LegalsFriday, 31 May 13

Page 18: Fel presentation

Add Icons

Friday, 31 May 13

Page 19: Fel presentation

Choose your weapon

Friday, 31 May 13

Page 20: Fel presentation

Implementation Techniques(On & Off the Critical Path)

1. Synchronous, external

2. Synchronous, inline

3. Simple async solution

4. Local Storage async

5. Async and defer to 2nd page

Friday, 31 May 13

Page 21: Fel presentation

Synchronous, external

@font-face { font-family: 'MyWebFont'; src: url('webfont.eot'); /* IE9 Compat Modes */ src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('webfont.woff') format('woff'), /* Modern Browsers */ url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */ url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */ }

http://www.fontsquirrel.com/tools/webfont-generator

Friday, 31 May 13

Page 22: Fel presentation

Synchronous, inline• WOFF can be base64 encoded and inlined.

• Slower perceived speed

• Don’t serve it to IE!

<!--[if (gt IE 8) | (IEMobile)]><!--> <link href="common_core_with_base64.css" media="all" rel="stylesheet" type="text/css" /><!--<![endif]-->

<!--[if (lt IE 9) & (!IEMobile)]> <link href="common_core_without_base64.css" media="all" rel="stylesheet" type="text/css" /><![endif]-->

Friday, 31 May 13

Page 23: Fel presentation

Simple Async var f, x;

x = document.getElementsByTagName("script")[0];

f = window.document.createElement("link");

f.rel = "stylesheet";

f.href = "#{asset_path("woff.css")}"; window.setTimeout(function(){ x.parentNode.insertBefore(f, x); },0)

• Don’t forget to factor in non-woff versions

Friday, 31 May 13

Page 25: Fel presentation

Async & Defer // HEADER if fonts_are_cached do <link href=”woff.css” rel=”stylesheet” /> end

// FOOTER if !fonts_are_cached do <script> // Load in custom fonts $.ajax({ url: '#{asset_path("woff.css")}', success: function () { // Set cookie } }); </script> end

Read more: http://css-tricks.com/preventing-the-performance-hit-from-custom-fonts/

Friday, 31 May 13

Page 26: Fel presentation

Which is difficult if you’ve added icons...

Friday, 31 May 13

Page 27: Fel presentation

What next?

• Client hints, connectionType and its blatant misuse

• Browsers giving authors the option of how to render a custom font

Friday, 31 May 13

Page 28: Fel presentation

Thanks, any questions?

Friday, 31 May 13