βš”οΈ The Great Streaming Quest 🏰

A Cloudflare Workers Demo for HTML Streaming Performance

🦸 Hero = Browser
πŸ§™ Quest Giver = Server
πŸ—ΊοΈ Map = <head> tag
πŸ›‘οΈ Heavy Armor = CSS/JS
πŸ”οΈ Dungeon = Database
πŸ’° Treasure = <body> data

This demo shows how streaming the <head> before the <body> improves page load performance. The browser can download CSS, fonts, and JS in parallel while the server fetches data.

οΏ½ Race: Streaming vs Traditional

πŸš€ Why Stream the <head>?

βœ… With Streaming

Browser receives <head> instantly.
Downloads CSS/JS in parallel with server work.
Total: ~2000ms

❌ Without Streaming

Browser waits for entire response.
Downloads CSS/JS after server finishes.
Total: ~2800ms

How it works: The Worker uses TransformStream to send the <head> immediately via ctx.waitUntil(), then continues fetching data. The browser parses the <head> and starts downloading CSS/JS assets while the server is still working.