Peter Müller
Dad, Cancer survivor, web tooling radical. @Assetgraph maintainer, Mochajs core member, Open source enthusiast and public speaker
Peter Müller - @_munter_
Users can instantly consume the most important parts of your page
<!doctype html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Noto+Serif:400,700,400i|Open+Sans:700,400">
</head>
...
</html>
Recommended by Google Fonts
<link
rel="preload"
as="font"
type="font/woff2"
crossorigin="anonymous"
href="https://fonts.gstatic.com/blahblah.woff2"
>
Starts download immediately
Requires known URI
Font service URI's not guaranteed stable
Serve your own fonts
Easy
Progressive enhancement
Â
Can be sent as HTTP-Header:
Link: </fonts/Roboto.woff2>; rel=preload; as=font; type=font/woff2;
Browser Usage: 59.79%
var font = new FontFace(
'Roboto',
'url(/fonts/Roboto.woff2) format("woff2"), url(/fonts/Roboto.woff2) format("woff2")',
{
weight: 700,
stretch: 'normal'
}
)
font.load().then(...)
Browser choses the format it supports
Only with JS enabled
Â
Verbose syntax
Widens browser support
Â
Doesn't clash with <link rel="preload"> (use together)
Â
Multiple format support
Browser Usage: 85.36%
Browser Usage: 53.52%
Â
Difficulty level: Pandoras Box
Text nodes, html attributes, list counters, different browser default stylesheets, CSS specificity, CSS content, quotation marks, text-transform, transitions, animations, CSS states (:hover et al), media queries, conditional comments, noscript, "bolder" and "lighter" font-weight
Â
And many many more...
Â
Automation is needed: An unsolved problem
Source: Bram Stein - Web Font Anti-Pattern: Aggressive subsetting
Defining fallbacks
/* unicode range for font */
@font-family {
unicode-range: U+0-10FFFF;
}
/* Prepending new font name */
@font-family { font-family: font; }
@font-family { font-family: font_subset; }
p { font-family: font_subset, font, sans-serif; }
Â
Each time you need new characters
Static analysis has to have static data to parse
By Peter Müller
Dad, Cancer survivor, web tooling radical. @Assetgraph maintainer, Mochajs core member, Open source enthusiast and public speaker