Fetching my blog

Apparently I fucked up hard with the fetching logic of my blog posts. I host it on GitLab and I first need to fetch the repo file list and then fetch posts one by one.

The problem here is that Svelte is doing this for every pre-rendered page. This means for every blog post list page and for every post page. So, if I have 20 posts and 10 post titles per post list page, it makes it (20 + 2) * 20 = 440 requests to generate 22 pages. Fucking insane.

I came up with a simple solution. Feels hacky, but it works. In the pre-build stage, I do the fetching of all the data and write it in a file in /tmp directory, which is available on Netlify until the end of the build stage. In the server-side code, I just try to import these files first instead of making requests.

This discovery was a bit mind-blowing for me. Kind of makes sense if you think of it. But it just didn't occur to me while I coded it. Probably because I had several posts and this small batch of requests was going unnoticed.