I'm curious about how to optimize website loading performance by deciding when to separate files like CSS, JS, or SVGs into individual files versus inlining them. I know having multiple HTTP requests can slow things down, but browsers can cache resources to speed up future loads. For example, if I'm using a simple SVG multiple times on a page, should I include the SVG code directly in the HTML or create a separate file? Also, is it better to combine CSS files and increase the initial load time for a page, knowing that it could be cached for faster subsequent page loads? Is there a threshold, like a certain file size in KB, that determines the decision?
5 Answers
Above all, don't sacrifice maintainability just for a bit of performance gain. It's usually better to keep things clean and use automated solutions for speed.
In the past, we kept a small CSS file for quick initial loads and then loaded the larger CSS afterward. It made sure the first paint was speedy without sacrificing performance on subsequent loads.
With HTTP/2, the drawbacks of having many small files aren't as significant anymore. Generally, a good guideline is to inline anything below 4KB. Repeating high-frequency elements should be fine since gzip compression helps a lot. Just remember that there’s no one-size-fits-all answer; testing your specific case is key to optimizing performance.
You can use tools like Gulp to generate specific CSS and JS files for each page, ensuring that only the necessary code is loaded. This keeps things optimized while still maintaining structure where possible.
Actually, with the advancements in HTTP/2, making large monolithic files can be counterproductive. They might complicate builds and delay first render times. Better to stick with a setup that updates efficiently.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads