mvasigh / sveltekit-mdsvex-blog

A minimalistic blog template built with SvelteKit and MDsveX

Home Page:https://sveltekit-mdsvex-blog.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Performance issues at scale

babichjacob opened this issue · comments

commented

Right now, this template is set up to load all blog posts' metadata and contents at once into the browser's memory:

const files = import.meta.glob('./*.{md,svx,svelte.md}');
/**
* @type {import('@sveltejs/kit').Load}
*/
export async function load({ page }) {
const slug = page.path.replace('/posts/', '');
const posts = await getAllPosts(files);
const post = fromEntries(posts)[slug];

This can be avoided by doing the same work in an endpoint instead: https://github.com/babichjacob/university-website/blob/84b5e7ff44550910550a3c809ccb9f1402df301b/src/routes/blog/index.json.ts#L6-L23
and fetching from that in the layout (or wherever it's needed, like to show the most recent 3 posts on the website's homepage and all posts on the website's /blog route): https://github.com/babichjacob/university-website/blob/84b5e7ff44550910550a3c809ccb9f1402df301b/src/routes/blog/index.svelte#L3

Thanks for opening this! That makes sense. I can go ahead and make this change.

@babichjacob I went ahead and merged #3 which addresses this, just let me know if there's anything I missed. Thanks!