# Performance

> Aegis is engineered for raw performance with a zero-base loading strategy. The theme loads zero CSS, JavaScript, or font assets by default — assets are loaded conditionally only when needed by the content on the page.

## Zero-Base Loading Strategy

Traditional themes load their entire stylesheet and script bundle on every page, regardless of what the page actually uses. Aegis takes the opposite approach:

1. **Default state:** No theme CSS, no theme JS, no web fonts loaded.
2. **Block detection:** During rendering, Aegis detects which blocks are present on the page.
3. **Conditional loading:** Only the styles and scripts required by those blocks are enqueued.
4. **Result:** Pages that use only core blocks may load with zero theme-specific assets.

### What This Means in Practice

| Page Content | Assets Loaded |
| --- | --- |
| Simple page with only paragraphs and images | Zero theme CSS/JS (core styles only) |
| Page with a Slider block | Slider CSS + Slider JS only |
| Page with Countdown + Toggle | Countdown CSS/JS + Toggle CSS/JS |
| WooCommerce product page | WooCommerce integration styles only |

## Conditional Asset Loading

### How It Works

The asset loading system operates in three phases:

1. **Registration** — All available assets are registered with WordPress but not enqueued.
2. **Detection** — Block parsing identifies which blocks and variations are present in the content.
3. **Enqueueing** — Only the assets required by detected blocks are added to the page.

### Block-Level Granularity

Each custom block and enhanced core block declares its own dependencies:

```
// Example: Slider block registers its own assets'style'        => 'aegis-slider',      // Frontend CSS'script'       => 'aegis-slider',      // Frontend JS'editor_style' => 'aegis-slider-editor', // Editor-only CSS
```

These assets are only loaded when the block appears on the page.

### Plugin Integration Styles

Plugin-specific compatibility styles follow the same pattern:

- WooCommerce styles load only on WooCommerce pages.
- LMS styles load only on course/lesson pages.
- Form styles load only when a form block is present.

## Font Loading Strategy

Fonts are a significant performance factor. Aegis optimizes font loading:

### Self-Hosted Fonts

All fonts (Lexend, Lexend Deca, JetBrains Mono) are served from the theme directory:

- No external requests to Google Fonts or other CDNs.
- Fonts are available immediately without DNS lookup or connection overhead.
- Full control over caching headers.

### Variable Fonts

Using variable font files reduces the number of HTTP requests:

- One file for Lexend covers weights 300–900.
- One file for Lexend Deca covers weights 300–900.
- One file for JetBrains Mono (`jetbrains` slug) covers weights 100–900, upright only.

### Font Display Strategy

Fonts use `font-display: swap`:

- Text is immediately visible using a system font fallback.
- Custom fonts swap in once loaded.
- No flash of invisible text (FOIT).
- Minimal flash of unstyled text (FOUT) due to similar font metrics.

### Conditional Font Loading

`theme.json` declares the font faces, and browsers download a `woff2` file only when text on the page uses that family:

- JetBrains Mono downloads only when code text is on the page.
- Lexend Deca downloads when headings are present.

## Image Optimization

Aegis supports WordPress native image optimization:

- **Responsive images** — `srcset` and `sizes` attributes for proper resolution selection.
- **Lazy loading** — Images below the fold use `loading="lazy"`.
- **Aspect ratio** — Explicit width and height attributes prevent layout shift.
- **WebP/AVIF** — Works with WordPress image format conversion.

### Video Facades

With the Aegis Video add-on active, the Video block uses a facade pattern:

1. A lightweight thumbnail image is displayed initially.
2. The video player (iframe or native) loads only when the user clicks play.
3. This eliminates heavy third-party script loading on page load.

Facades only play YouTube (`youtube.com`, `youtube-nocookie.com`) and Vimeo (`player.vimeo.com`) player URLs over HTTPS. Other embeds render as normal, without a facade.

## Pattern and Icon Loading

Since 1.0.2, Aegis no longer runs every pattern file or lists every icon on each request.

| Item | What Aegis does | Cache |
| --- | --- | --- |
| Patterns | Reads only each file’s header and registers the pattern with its file path. WordPress runs a pattern file only when its content is used. | `aegis_pattern_headers` option (not autoloaded) |
| Icons | Lists each icon folder’s SVG file names once (about 5,700 files) | `aegis_icon_files` option (not autoloaded) |

How the caches stay current:

- A folder is listed again when its modified time changes. Adding, removing, or renaming a pattern or icon does that.
- The editor, the REST API, and WP-CLI re-read a pattern’s header when its file changes. Front-end requests use the cached headers. Pattern content is always read from the file.
- If a template asks for a pattern slug that is not registered, that request re-checks every pattern file, so a renamed slug works on the front end right away.
- The pattern cache starts fresh when the active theme or its version changes, so a theme update never serves old pattern headers.

The gain is largest on hosts that restrict file access with `open_basedir`, where each file check is costly. WooCommerce’s variation scripts (`underscore`, `wp-util`, `wc-add-to-cart-variation`) also load only where a variable product form needs them.

You do not need to clear these caches. Edits to a pattern’s content show right away. A changed header (title, categories, slug) is picked up the next time the editor, REST API, or WP-CLI loads the pattern list.

## Critical Rendering Path

Aegis minimizes render-blocking resources:

| Resource Type | Loading Strategy |
| --- | --- |
| Theme CSS | Conditional, only per-block styles |
| Theme JS | Deferred, conditional per-block |
| Fonts | Preloaded for above-the-fold content |
| Images | Lazy loaded below the fold |
| Videos | Facade until interaction |
| Analytics | Async/defer, non-blocking |

## Measuring Performance

### Core Web Vitals

Aegis is optimized for Google Core Web Vitals:

| Metric | Target | How Aegis Helps |
| --- | --- | --- |
| LCP (Largest Contentful Paint) | < 2.5s | Minimal CSS, font preloading, no JS blocking |
| FID (First Input Delay) | < 100ms | Deferred JS, minimal main-thread work |
| CLS (Cumulative Layout Shift) | < 0.1 | Explicit image dimensions, font-display swap |
| INP (Interaction to Next Paint) | < 200ms | Lightweight event handlers, no heavy frameworks |

### Testing Tools

| Tool | Purpose |
| --- | --- |
| WPAudit | WordPress-specific performance audit |
| Lighthouse | General web performance scoring |
| WebPageTest | Detailed waterfall analysis |
| PageSpeed Insights | Field data + lab data analysis |

### Running WPAudit

```
composer test:wpaudit
```

See [Testing](https://www.atmostfear-entertainment.com/docs/aegis/themes/theme/testing/) for more details on running performance tests.

## Caching Compatibility

Aegis works with all major caching solutions:

- **Page caching** — Full page cache safe (no user-specific content in templates).
- **Object caching** — Compatible with Redis and Memcached.
- **CDN** — All static assets use cache-friendly URLs.
- **Browser caching** — Assets include proper cache headers.

## Bundle Size

The theme produces minimal asset bundles:

| Asset | Typical Size |
| --- | --- |
| Per-block CSS | 1–5 KB (gzipped) |
| Per-block JS | 2–10 KB (gzipped) |
| Font file (variable) | 30–60 KB (per family) |
| Total typical page | Under 50 KB theme assets |

## Developer Performance Tips

When building custom pages or templates:

1. **Prefer core blocks** — They have zero theme asset cost.
2. **Minimize custom block usage** — Each custom block adds its CSS/JS bundle.
3. **Use patterns** — Patterns are just block markup, not additional assets.
4. **Avoid global stylesheets** — Do not add blanket CSS that loads everywhere.
5. **Test with Lighthouse** — Verify performance after significant changes.

## Next Steps

- [Aegis Dash Performance](https://www.atmostfear-entertainment.com/docs/aegis/plugins/dash/performance/) — Free site-wide toggles (oEmbed, dashicons, heartbeat, head/API cleanup, embed facades) and Pro emoji / Query Loop Performance. With Pro active, the theme defers emoji stripping to that toggle; free-plugin and standalone theme installs keep zero-base frontend emoji removal. Standalone theme enables embed facades by default; with Aegis Dash they default off until toggled.
- [Testing](https://www.atmostfear-entertainment.com/docs/aegis/themes/theme/testing/) — Running performance tests
- [Building Assets](https://www.atmostfear-entertainment.com/docs/aegis/themes/theme/building-assets/) — Understanding the build process.
- [Deployment](https://www.atmostfear-entertainment.com/docs/aegis/themes/theme/deployment/) — Production deployment considerations.

---

Source: https://www.atmostfear-entertainment.com/docs/aegis/themes/theme/performance/ · Updated 2026-11-24
