#html streaming astrojs

3 messages · Page 1 of 1 (latest)

molten questBOT
#

Hi @peak ore. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro supports HTML streaming, which can significantly improve the performance of your website by sending the HTML to the browser as soon as it's ready, instead of waiting for the entire page to render.

Here's an example of how you can use HTML streaming in Astro:

---
---
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<meta name="viewport" content="width=device-width" />
		<meta name="generator" content={Astro.generator} />
		<title>Astro</title>
	</head>
	<body>
		<h1>Astro</h1>
                {fetch(import.meta.env.SITE + '/foo.html').then(r => r.body)}
	</body>
</html>

In this example, the fetch() function is used to get HTML from an external source. The .then(r => r.body) part of the code takes the response from the fetch request and streams the body of the response, which is the HTML content.

Please note that the actual behavior might vary depending on the environment where your Astro application is running. For instance, in some environments like Netlify Edge, the streaming might not work as expected due to certain limitations or differences in the environment's implementation of streaming.

For more details, you can refer to the following sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@peak ore kapa.ai is still learning and improving, please let us know how it did by reacting below