🕵️ Reverse EngineeringHow not to solve Jane Street's ASIC puzzle. Kinda.(17.09.2026 um 21:27 Uhr)
🔧 ProgrammierungHTMX is fine until the third stakeholder wants a modal(17.09.2026 um 21:13 Uhr)
🕵️ Reverse EngineeringHow not to solve Jane Street's ASIC puzzle. Kinda.(17.09.2026 um 21:27 Uhr)
🔧 ProgrammierungHTMX is fine until the third stakeholder wants a modal(17.09.2026 um 21:13 Uhr)
🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

A short guide to Async Components in Svelte 5

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

I couldn't find any working solution for this online, so I thought to share it when I got it to work.






The Problem: Asynchronous Components



I needed a maintenance page that would take over the entire site when enabled, but loading it on every page visit seemed wasteful. The component should only load when actually needed.






The Solution: Combining {#await} with Dynamic Imports



The {#await} block in Svelte lets you handle promises right in your template. Pair that with dynamic import() for lazy-loading, and you've got yourself a concise and clear way to handle async components.



Here's the code:




CODE
<script>
// info.maintenance (boolean) && info.maintenance_ends (timestamp)
export let info;
const MaintenanceComponent = info?.maintenance
? import("$lib/components/Maintenance.svelte")
: null;
</script>

{#if MaintenanceComponent}
{#await MaintenanceComponent then M}
{@const Maintenance = M.default}
<Maintenance time={info.maintenance_ends} />
{:catch error}
<p>Failed to load maintenance page: {error.message}</p>
{/await}
{/if}









What's happening here?





  • Dynamic Import: I used import() to load the Maintenance.svelte component asynchronously. This makes sure the component is only loaded when maintenance mode is turned on.


  • {#await} Block: This block allows me to await the import.


  • {@const}: Svelte 5 introduces {@const} within templating blocks, which allows you to extract the default export (M.default) into a local variable.



Pro tip: Keep async operations out of $effect runes – they don't play well together, and TypeScript will let you know about it.



Happy Hacking!

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Microsoft gibt Fehler zu – Vorsicht! Windows-Update sperrt Nutzer vom PC aus - Heute.at
1 Quelle
How not to solve Jane Street's ASIC puzzle. Kinda.
1 Quelle
Revolut-Hacker fordern 6.000 Monero nach Datendiebstahl - Kryptorevolution
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten A short guide to Async Components in Svelte 5

Thematisch verwandte Begriffe: short, guide, Async, Components · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...