Skip to content

hamzaerbay/web-font-loading-recipes

 
 

Repository files navigation

web-font-loading-recipes

A bunch of demos for different web font loading strategies. Some of these are included on A Comprehensive Guide to Font Loading Strategies, some of them are more experimental.

Demos are hosted at https://www.zachleat.com/web-fonts/demos/

Recommended Methods

As web fonts are a progressive enhancement and with increasing support for the CSS Font Loading API, we can look forward to a time in which we won’t need to inline a polyfill into the header (for even faster font loading). The simplified CSS Font Loading API recipes are the defaults, but polyfilled versions are included for broader browser support. In practice this means only the polyfilled versions will show web fonts in Internet Explorer and Edge web browsers (which do not have support for the CSS Font Loading API).

Experiments in Progress

You’ll probably see blog posts on these at some point.

  • FOUT metric matching with a Variable Font
    • Reduction in FOUT reflow (reduce text movement on web font render)
    • Related: Font style matcher from @notwaldorf
  • Emulate font-display: optional with JS (the eBay method)
    • Notable in that it lazy loads the font loading polyfill only if the CSS Font Loading API is not supported
  • (To be named) Any recommended non-polyfilled recipe above with one slight variation: it uses the eBay method if the CSS Font Loading API is not supported (in practice this means font-display: optional only on IE/Edge). This is what I’m currently doing on zachleat.com.
  • FOUT without a class
    • Doesn’t require any modification of the CSS, injects the web fonts using JS programmatically (the Asynchronous Data URI method below also does this). Documented in the Webfont Handbook from @bramstein.

Not Recommended but included for Posterity

Deprecated Methods

Failed Experiments

  • @supports and font-display
    • Reasons for trying:
      • might be nice to only use web fonts if you can FOUT with font-display
      • might be nice to have FOUT with a class if font-display not supported (and work well without JS dependencies)
    • Failed: @supports doesn’t work with font-face descriptors.
    • Demo

** Take note that these methods will FOUT in Internet Explorer and Edge by taking advantage of their default font loading behavior.

Releases

No releases published

Packages

No packages published

Languages

  • HTML 100.0%