惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

ByteofDev

Making Postgres 42,000x slower because I am unemployed A Quick(ish) Introduction to Tuning Postgres JavaScript numbers have an (adoption) problem My 2025 JavaScript Wishlist JavaScript Benchmarking Is a Mess Replacing Disqus Commenting A deep dive into distributed database architectures 10 ways to speed up web image loading Tailwind has a scalability problem. How can we solve that? Lerna vs Turborepo vs Rush: Which is better in 2023? The 6 JavaScript Projects to watch in 2023 Top 5 Alternatives to React in 2023 How to use ESM on the web and in Node.js React vs Svelte: Which is better in 2023? 10 ways to speed up JavaScript loading What is Bun, and does it live up to the hype? State of JS 2021 Results and Analysis State of the Web: React 10 ways to speed up web font loading State of the Web: Atomic CSS State of the Web: Static Site Generators State of the Web: Bundlers & Build Tools State of the Web: Serverless Functions State of the Web: Deno Array.map() versus Array.forEach() A quick introduction to JavaScript Maps How I Built the Fastest JavaScript Data Differ State of the Web: WebAssembly When you should and shouldn't use React
Migrating ByteofDev from SvelteKit to Astro
Jacob Jackson · 2022-01-24 · via ByteofDev

Astro and SvelteKit are both modern frameworks. Originally, I built my blog ByteofDev using SvelteKit, but I recently migrated to Astro due to performance and tools for writing. This article talks about why I did it and how.

Why we migrated to Astro

Performance

ByteofDev's Scores using Lighthouse

Astro supports component-level partial hydration, which Astro based on the Islands Architecture. Component hydration is much more granular than SvelteKit’s page hydration because you can isolate JavaScript to one specific part of the page rather than either shipping JavaScript for the whole page or no JavaScript period. Partial hydration helped heavily reduce the JavaScript shipped to the client, significantly improving performance.

While doing this, I also was trying to migrate from a headless CMS to using markdown and Git to allow for more flexibility and performance. For markdown with Svelte components, Svelte has mdsvex, which works pretty well, but Astro has officially supported integration with MDX (which is what inspired mdsvex), which I found easier to use. Astro also has an easy-to-use API for getting the frontmatter of markdown files (Astro.glob()), making it easy to implement features like tag pages. Finally, Astro an easy-to-use plugin for sitemap and RSS feed generation, which is helpful for SEO and reaching a wider range of readers.

Migrating to Astro

Overall, migrating to Astro was not overly complex, as both Astro’s JSX and Svelte mainly use HTML. Additionally, some Svelte components I could keep as Svelte components. However, there were still a few hitches.

Frontmatter

In Svelte, all frontmatter is handled inside <script> tags. However, in Astro, this is not the case. In Astro, you put everything in ---, like markdown frontmatter. There were also differences in loading data and displaying it due to the differences in API (this was exemplified due to also moving away from a CMS). Finally, with SvelteKit, there is a <svelte:head> component, which does not exist in Astro. It is possible to use slots in Astro, but ultimately I settled on using a custom SEO component like Astro SEO.

Conditionals and iteration

SvelteKit has a custom syntax for iterating through elements and using conditionals, whereas Astro follows JSX and uses embedded JavaScript expressions. For example, a conditional in Svelte might look something like this:

{#if boolean}
<h1>The boolean is true</h1>
{/if}

Where in Astro, you would do something like this:

{
	boolean ? <h1>The boolean is true</h1> : "";
}

When iterating through an array, it is also different. For Svelte, you would do this:

{#each array as item}
<div>
	<h2>{item.name}</h2>
	<p>{item.description}</p>
</div>
{/each}

For Astro, the best way to iterate through an array is usually this:

{
	array.map((item) => (
		<div>
			<h2>{item.name}</h2>
			<p>{item.description}</p>
		</div>
	));
}

These differences made it harder to migrate, but it was pretty simple to change it still.

API Endpoints

SvelteKit has built-in support of API Endpoints, but Astro does not. I reduced the number of endpoints I needed, but I still needed one for signing up for the ByteofDev mailing list. This is where a recent development helped me. Fullstack pages, a new feature in Cloudflare Pages, made it significantly easier to set up an API Endpoint compared to using a Worker. It still was not as easy as using SvelteKit’s integration with Cloudflare, and the endpoint does not run in development, but overall it works pretty well. If you are using Netlify, Netlify Functions or Edge will work. If you are using Vercel, Vercel Serverless Functions should work.

Conclusion

Moving from SvelteKit to Astro has benefited my blog because of the features provided and the performance. Using Astro, I reduced my server hosting costs by eliminating the CMS and reducing Cloudflare Worker requests to only one route while improving performance by reducing the JavaScript sent (see Lighthouse scores above). If you liked this article, sign up for the newsletter below. I hope you have learned something from this, and thank you for reading.