Failing is better than not trying

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

I've wanted to optimize my website even more for the longest time. Every weekend I try to dedicate some time to see where I can optimize it even more.
This weekend it was all around CSS loading. It's already pretty optimized, and there were only two items I could think of.
Unfortunately, this is not supported with Tailwind in Astro as we get one generic output CSS. For my website, it doesn't make the biggest difference as the post pages only have a couple of lines of extra CSS compared to the homepage.
However, still looking at how I can optimize what's used even more.
Conclusion: Nothing to optimize for a quick win. More research is needed.
I wasn't sure if this one would help, but we could declare the main stylesheet as important by adding a rel="preload" link.
This would indicate that the page should try and fetch this with the most priority.
It sounded easy to try out, but it took a lot of research and trying out things.
I went over the Astro docs and found out you can load the stylesheets as a plain URL by appending a ?url parameter.
Then, we can load it directly like this:
---
import stylesUrl from '../styles/main.css?url';
---
<link rel="preload" href={stylesUrl} as="style">
<link rel="stylesheet" href={stylesUrl}>
The dev version worked perfectly, but then I tried outputting this as a build, and I noticed it base64 encoded the whole CSS file.
It is documented in the docs this can happen, and we have to disable this Vite config.
I added the following to my astro.config.mjs file:
export default defineConfig({
vite: {
build: {
assetsInlineLimit: 0,
},
},
});
I reran my build output and ended up with a compiled CSS like this:
@tailwind base;
@tailwind components;
@tailwind utilities;
.some-of-my-custom-css {
// ...
}
Ugh, not really what I wanted as our Tailwind is not processed now.
I took one of my existing build compiled CSS files for option three and put them in my project.
Note: My CSS doesn't ever change, so that it could be a viable option.
I changed my imports to load this CSS file, and voila, it worked!
Eagerly I went to try my tests again to see how fast it was loading. To my disappointment, it went backward. It now took another 2ms longer to load the first byte.
And thus, back to the drawing board with CSS optimizations.
Sometimes you might have put a lot of work into something that does not work as you expected.
It's totally fine, and it happens to everyone. At least you learned something, and you tried it out.
I generally don't write as much about my failed experiments, but I thought it might help other people not to feel bad when something doesn't work on the first try.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter