Performance: Progressive enhancement
Progressive enhancement improves initial page load speed and interaction readiness by delivering basic content first and layering advanced features later.
<script> let showWidget = false; let HeavyWidget; async function loadWidget() { const module = await import('./HeavyWidget.svelte'); HeavyWidget = module.default; showWidget = true; } </script> <button on:click={loadWidget}>Load Widget</button> {#if showWidget} <svelte:component this={HeavyWidget} /> {/if}
<script>import HeavyWidget from './HeavyWidget.svelte';</script> <HeavyWidget />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Immediate full JS load | High (many nodes from full component) | Multiple reflows during load | High paint cost due to complex layout | [X] Bad |
| Basic HTML first + lazy JS | Low (simple DOM initially) | Single reflow when JS loads | Low paint cost initially | [OK] Good |
progressive enhancement in Svelte applications?Enable JavaScript to see this app.
uses correctly with fallback text. Others misuse tags or won't show fallback properly.<button aria-label="Toggle menu" on:click={toggleMenu}>Menu</button>
<nav class:open={menuOpen}>...</nav><button on:click={toggle} aria-expanded={expanded}>Toggle</button>
<div hidden={!expanded}>Content</div>Pass the test and this pattern moves unknown