Skip to content

thedaviddias/Front-End-Checklist / skills/font-loading

font-loading

Verified

Use when auditing slow page loads, heavy assets, or rendering delays related to Optimize web font loading. Verify the actual bottleneck in DevTools, Lighthouse, or field data before recommending changes.

FileKindSize
SKILL.mdskill md1.6 KB
references/rule.mdmarkdown3.9 KB

references/rule.md

View on GitHub
# Optimize web font loading

> Use efficient font formats and loading strategies to prevent layout shifts and invisible text.

**Priority:** high · **Difficulty:** intermediate · **Time:** 15 min

---
Fonts are often discovered late by the browser because they are referenced inside CSS files. Optimizing how they are fetched and rendered is key to a stable and fast UI.

## Code Examples

#

## 1. Using `font-display: swap`
This tells the browser to show the fallback font immediately and swap it once the custom font is ready.

```css
@font-face {
  font-family: 'MyCustomFont';
  src: url('/fonts/my-font.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap; /* Crucial for performance */
}
```

### 2. Preloading Critical Fonts
Place this in your `<head>` to start the download as soon as possible.

```html
<link
  rel="preload"
  href="/fonts/my-font.woff2"
  as="font"
  type="font/woff2"
  crossorigin
>
```

### 3. Self-Hosting for Performance
Self-hosting fonts eliminates extra DNS lookups and TLS connections to third-party providers like Google Fonts.

```css
/* Better than linking to external CSS */
@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-subset.woff2') format('woff2');
}
```

## Why It Matters

- **Visual Stability**: Prevents layout shifts when a custom font replaces a fallback font with different dimensions (CLS).
- **Perceived Speed**: Using `font-display: swap` ensures users can read content immediately using a system font while the custom font loads.
- **Bandwidth Efficiency**: Modern formats like WOFF2 offer significantly better compression than older formats like WOFF or TTF.
- **Discovery Time**: Preloading fonts allows the browser to start the download before the CSS has even been parsed.

## Best Practices

Verify the font waterfall in [PageSpeed Insights](https://pagespeed.web.dev/) or DevTools after each change, because good font loading is about earlier discovery and stable fallback metrics rather than just flipping `font-display: swap`.

✅ **Use WOFF2**: It is the most efficient format and is supported by all modern browsers.
✅ **Subset Your Fonts**: Only include the characters you actually need (e.g., Latin characters only) to reduce file size.
✅ **Limit Font Variations**: Avoid loading every weight (100, 200, 300, etc.) if you only use Regular and Bold.
✅ **Variable Fonts**: Use a single variable font file instead of multiple separate files for different weights.

❌ **Don't Use FOIT**: Avoid the default browser behavior of hiding text until the font loads (Flash of Invisible Text).
❌ **Avoid Base64 Inlining**: Inlining fonts as Base64 in your CSS increases the CSS file size and prevents the font from being cached separately.

## Tools & Validation

- Google Fonts Helper can speed up self-hosting work when you need a quick export of font files and matching CSS.
- [FontSubsetter](https://font-subsetter.com/): Reduce font file size by removing unused characters.
- [Lighthouse](https://developer.chrome.com/docs/lighthouse/overview/): Checks if "All text remains visible during webfont loads."
- [Web Font Configurator](https://wakamaifondue.com/): Analyze what's inside your font files.

## Standards

- Use web.dev: Learn Performance as the standard for measuring the final production behavior, not just local synthetic output.
- Use Chrome Developers: Lighthouse overview as the standard for measuring the final production behavior, not just local synthetic output.

## Verification

### Automated Checks

- Measure the affected page or flow in Lighthouse, PageSpeed Insights, or DevTools and confirm the targeted metric improves.
- Inspect the network waterfall or performance timeline to confirm the intended resource or execution change actually took effect.

### Manual Checks

- Verify the change on a throttled mobile profile, not just local desktop.
- If this rule maps to a budget or Web Vital, confirm the page now stays within that threshold.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall