In ~1 month, astro-font has grown to 5.7K downloads 🤯
Checkpoint #1
It all began with me thinking about what is missing from the Astro ecosystem? After checking out some of the websites (including my own hybrid Astro website, launchfa.st), I found that an end to end font optimization library was missing 👇
Checkpoint #2
So, I actually set out to built an Astro package that’ll deliver the promise. I thought it’d be super easy to just use the scripts @vercel’s next/font does and ship it (and I did that very initially!). It worked great for static websites! BUT, enter SSR websites👇
Roadblock #1
next/font being coupled with the build process of Next has access to the output directories and the expected runtime configuration and thus it self-hosts fonts even in SSR-first websites. This space got more complex for Astro SSR websites as astro-font is an Astro component and not an Astro integration! Here’s what I did to solve that problem 👇
Roadblock #2
Great! That worked and allowed me to determine if the SSR build had fonts shipped with it and thus allowing me to compute the fallback font at the runtime. BUT, some users wanted to use CDN URLs or were using fontsource fonts. There was no way to possibly know to what Vite resolved the internal fonts to. Hence, I built a runtime Google Fonts-like CSS parser 👇
Checkpoint #3
Seems complete, right? It now works with local fonts and fonts over CDN. But runtime fetch + compute is gonna cost us SSR time. To solve that, enter runtime font caching 👇
Checkpoint #4
Now? We’re just left with one thing to do. Allow per font per config preloads (and backward support to global preloads (not))!
Thank you for that awesome package... it helped me fight the "layout shift"! I will add it to Best of JS, as we have a tag `Astro` https://t.co/38Akqa5IQd