• Stars
    star
    1,057
  • Rank 43,651 (Top 0.9 %)
  • Language
    HTML
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A bunch of demos for different web font loading strategies. Companion to https://www.zachleat.com/web/comprehensive-webfonts/

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/

Table of Contents

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—notably 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).

font-display: swap

preload

font-display: swap with preload

FOUT with a Class

FOUT

Similar to the above, but without using a class—using only the CSS Font Loading API. This doesn’t require any modification of the CSS, injects the web fonts using JS programmatically. I first saw this method in the Webfont Handbook from @bramstein.

  • JavaScript: CSS Font Loading API
  • Code
  • Demo (4 web fonts)
  • Related: .style.fontFamily method (only works well with one family per page), first saw this in a tweet from @simevidas

FOFT

Two stage load, using one Roman font file in the first stage (with font-synthesis).

Critical FOFT

Critical FOFT with Data URI

Critical FOFT with preload

The eBay Method

“The Compromise”: Critical FOFT with preload, with a polyfill fallback emulating font-display: optional

Further Enhancements

These aren’t necessarily font loading strategies on their own but they are extra enhancements you can layer on top of and pair with existing strategies.

Network Information API

Opt out of web fonts on slow connection speeds.

prefers-reduced-motion User Preference

Opt out of web fonts when user has enabled Reduce Motion accessibility preference.

save-data User Preference

Opt out of web fonts when user has enabled Data Saver mode.

Experiments in Progress

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

Not Recommended but included for Posterity

font-display: optional

  • A little harsh to put this in the Not Recommended section but I like my web fonts on an empty-cache visit 😎
  • Code
  • Demo** (4 web fonts)

System fonts

C’mon. 😇

Unceremonious Web Fonts

Unceremonious Web Fonts, WOFF2 Only (Cutting the Mustard)

Old browsers used to render FOIT without a timeout, which in practice made web fonts a single point of failure. Using WOFF2 only cuts the mustard to modern browsers that have a three second FOIT timeout for web fonts. We’re anti-invisible text here, but this approach is worth mentioning.

Unceremonious Faux Web Fonts

font-synthesis is not a good end-product.

Anti-patterns and Deprecated Methods

⚠️ Inline Data URI

⚠️ Asynchronous Data URI

⚠️ <style> Injection

Anything that uses JavaScript to inject a new <style> with @font-face blocks inside. Really bad repaint cost—avoid this. This is used in the Asynchronous Data URI method above but is also common in worse-performing methods too.

⚠️ font-display: optional and preload

⚠️ FOFT using only font-display (mixing font-display values across a font-family)

This method does not currently have cross-browser support. I’m hoping this will change—learn more.

  • Code
  • Demo** (4 web fonts—1 swap / 3 optional)

Failed Experiments

🚫 Asynchronous CSS

This is a common thing people try—they asynchronously load the CSS (and only the CSS). Heck, I used this behavior before I started studying web font loading.

🚫 @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.
  • Code
  • Demo

🚫 font-family Stack

  • Put two or more font-family web fonts in a single font-family stack.

  • Failed: The font matching algorithm selects the first web font that matches and attempts to load it (ignoring subsequent web font families). Even if you preload the subset first stage, it’ll swap over due to font-family order priority.

  • Code

  • Demo

  • Update: While you can mitigate the above problem with font-display, perhaps modifying the order of the font-family stack and @font-face block ordering, there are still problems with removing the unnecessary subset web font from the page after the larger version has loaded. Font features that occur with glyphs that cross these font file boundaries will be broken (kerning, ligatures, et cetera). Relatedly, you cannot remove a CSS-paired FontFace object using the CSS Font Loading API (per the specification).


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

More Repositories

1

speedlify

Benchmark the web performance and accessibility of sites over time.
JavaScript
923
star
2

BigText

jQuery plugin, calculates the font-size and word-spacing needed to match a line of text to a specific width.
JavaScript
886
star
3

fontfaceonload

A simple utility to execute a callback when a webfont loads.
JavaScript
372
star
4

table-saw

A small web component for responsive <table> elements.
HTML
312
star
5

details-utils

A suite of utilities to add more features to the <details> element.
JavaScript
258
star
6

browser-window

Used in demos as a way to fake a Safari-esque web browser window.
JavaScript
249
star
7

zachleat.com

zachleat.com is powered by Eleventy and WebC.
JavaScript
192
star
8

Humane-Dates

Show the difference between a date and now (4 days ago)
JavaScript
186
star
9

carouscroll

Add next/previous buttons to a horizontal scrollable container.
HTML
116
star
10

performance-leaderboard

A plugin to run Lighthouse against a set of urls to see which site is the fastest.
JavaScript
96
star
11

postcss-foft-classes

A postcss plugin to automatically add classes for various font loading strategies.
JavaScript
90
star
12

seven-minute-tabs

A minimal no-theme Tabs web component.
JavaScript
87
star
13

filter-container

Filtering visible child elements based on form field values.
HTML
84
star
14

video-radio-star

A lightweight web component helper for HTML5 videos.
HTML
73
star
15

font-family-reunion

Compatibility tables for default local fonts.
HTML
67
star
16

spider-pig

Get a list of local URL links from a root URL.
JavaScript
67
star
17

snow-fall

A web component to add snow to your web site (or to an element on your web site).
JavaScript
67
star
18

announcement-banner

An announcement banner web component.
HTML
50
star
19

speedlify-score

A web component that shows Lighthouse scores via Speedlify.
JavaScript
45
star
20

hypercard

Web component to add a three-dimensional hover effect to a card.
JavaScript
41
star
21

jQuery-Gravatar

Retrieve a gravatar image dynamically from any e-mail address.
JavaScript
37
star
22

squirminal

The squirminal is a fake antique terminal web component
HTML
37
star
23

bench-framework-markdown

A set of scripts to test markdown processing speeds in various site generators/frameworks
Shell
34
star
24

infinity-burger

A new kind of hamburger menu
JavaScript
31
star
25

queue-code

Allows you to “type” syntax highlighted source code for presentations and screencasts.
JavaScript
30
star
26

pagefind-search

A web component to search with Pagefind.
JavaScript
30
star
27

performance-leaderboard-pagespeed-insights

A plugin to run Lighthouse on Pagespeed Insights against a set of urls to see which site is the fastest.
JavaScript
27
star
28

esm-import-transformer

Change import URLs in JavaScript code using import maps. e.g. `import * from "before"` to `import * from "after"`
JavaScript
24
star
29

idea-book

A public dump of ideas for side projects, for public upvoting/downvoting/commenting.
24
star
30

selecthor

A better way to test, learn, and demo CSS selectors
HTML
24
star
31

github-issue-to-json-file

Convert a well formed GitHub Issue Form populated Markdown body into a JSON data file in the repository.
JavaScript
23
star
32

JavaScript-Code-Katas

Let's practice our JavaScript testing.
JavaScript
23
star
33

webcare-webshare

JavaScript
23
star
34

f2em.com

A Front End Engineer's Manifesto
JavaScript
22
star
35

avatar-local-cache

Saves a image URL for an avatar to the local file system (and optimizes the image).
JavaScript
21
star
36

performance-sometime

Improving the web font rendering of the default Wordpress theme.
JavaScript
20
star
37

this-website-is-a-tech-talk

HTML
20
star
38

educational-sensational-inspirational-foundational

A website dedicated to a history of foundational web development blog posts.
CSS
20
star
39

heading-anchors

Adds and positions sibling anchor links for heading elements (h1–h6) when they have an `id` attribute.
JavaScript
20
star
40

throbber

A loading indicator overlay for images (and maybe other things later).
JavaScript
15
star
41

artificial-chart

An SVG charting library based on D3.js
JavaScript
15
star
42

gruntlerplate

A default grunt configuration for new projects.
JavaScript
13
star
43

ToolOrDie

A presentation on Web Developer Workflow.
HTML
12
star
44

ALARMd

Web based alarm clock
JavaScript
12
star
45

node-retrieve-globals

Execute a string of JavaScript using Node.js and return the global variable values and functions.
JavaScript
11
star
46

parity-purchasing-power-price

Web Component to show Parity Purchasing Power prices.
JavaScript
11
star
47

font-stats

Generates useful information about a font from a font file.
JavaScript
10
star
48

w3c-banners

A non-image based non-normative proposal for conformance of W3C status banners.
HTML
9
star
49

rainglow

A demo for 11tymeetup.dev
Nunjucks
9
star
50

css-tricks-font-loading

A case study of the font loading for css-tricks.com
HTML
8
star
51

iliveinomaha-banner

Retina friendly progressively enhanced banner for iliveinomaha.com
CSS
7
star
52

foitfout

A web font loading demo to showcase FOIT and FOUT behavior side by side.
JavaScript
6
star
53

async-css-loading

Test cases for asynchronous css loading
HTML
6
star
54

JsTestDriver-Boilerplate

Easy boilerplate for test driven JavaScript projects using the JsTestDriver tool.
Shell
6
star
55

Compatibility-Tests

HTML5 tests used for research for blog posts
5
star
56

BUSYNESS

This project is retired.
JavaScript
5
star
57

uniclode

Another Eleventy Serverless demo, select characters to form a Unicode Range
JavaScript
5
star
58

Raging-Netflix-Queue

RETIRED—A Google Chrome extension, provides a single click add to your Netflix queue while browsing the web.
JavaScript
5
star
59

fundraising-status

Web component to show the current status of a fundraiser.
HTML
4
star
60

a-single-html-file

I am a single HTML file.
HTML
4
star
61

noop

A minimal module to test importing in other tools.
JavaScript
4
star
62

a11y-tests

A series of small atomic tests used to compare accessibility linting tools.
HTML
4
star
63

eleventy-components

4
star
64

unicode-range-interchange

Do math on Unicode Ranges for web fonts.
JavaScript
4
star
65

twitter-avatar-url

Find a twitter avatar image url from a twitter username.
JavaScript
4
star
66

demo-cloudcannon-image-optimization

JavaScript
4
star
67

netlify-kasa-build-status

A little script to update my lights with the status of a Netlify build
JavaScript
3
star
68

browser-logo-icon-set

A multi-color vector icon set (grunticon generated) of browser logos
HTML
3
star
69

DOM-Sailbloat

Find the bloat in your document using this Firebug Lite plugin.
JavaScript
3
star
70

rawhyde

A boilerplate for the Jekyll/Grunt/Buttsweater combination used on zachleat.com and nebraskajs.com.
JavaScript
3
star
71

Firebug-Code-Coverage

Retired source code for an old JavaScript Code Coverage plugin for Firebug.
JavaScript
3
star
72

tweetback-zachleat

HTML
3
star
73

Snapper

JavaScript
2
star
74

demo-eleventy-base-blog

Just testing GitHub templates
HTML
2
star
75

myspacebook

It’s out of this world.
JavaScript
2
star
76

Parlour

A full screen photo gallery with flickr integration.
JavaScript
2
star
77

package-zachleat

Meta package for Zach Leatherman
JavaScript
2
star
78

eleventy-sample-css-manager

Sample created for https://twitter.com/jaffathecake/status/1153759414765203463
JavaScript
2
star
79

gif-party

JavaScript
1
star
80

edge-redirects-test

HTML
1
star
81

zachleat

I AM A ✨ SPECIAL ✨ REPOSITORY
1
star
82

space-jam

HTML
1
star
83

reverse-proxy-test

HTML
1
star