Splitting your CSS into several files makes them a lot more manageable and increases usability for your developers. However, it will force every user to make an additional request to your server for each seperate CSS file and forces you to update your HTML code whenever you want to add / remove / rename a specific "group" of CSS.
Native CSS allows you to include other CSS files directly, so you could go the route of having one central "main" CSS that loads all the other styles:
<link rel="stylesheet" href="/stylesheets/main.css">
And in the main.css
:
@import "init.css";
@import "signup.css";
@import "navigation.css";
@import "upgrade.css";
@import "content.css";
This will keep all CSS-related grouping in a CSS file itself and out of the template code, but doesn't change the fact that a user now has to request a couple of different files where there was only one before.
An even better solution would be to use a CSS Preprocessor like SASS/SCSS, which allows you to include CSS files automatically and renders them (even with a smaller file size) in one single CSS file while maintaining individual source files on the development side. The above import
code would look like this with SCSS:
@import "init";
@import "signup";
@import "navigation";
@import "upgrade";
@import "content";
You would then put all your "init" CSS rules in a file called _init.scss
and run the SCSS preprocessor with scss -t compressed main.scss main.css
. This renders everything inline into a single main.css
file, ready to be delivered to your users via a single request to your server.