Well, there are two main schools of thought.
Firstly, it reduces the number of HTTP requests as much as possible. This will say to reduce ALL CSS files to one monster. Itβs better to download 400kb once than several 50kb files. (and the same for JS).
Another is to combine where necessary, but no further. If you have 100 KB of CSS that is needed in only one section of the site, there is no reason to slow down the rest of the site for your users. This is especially true for JS, since there are many sites on every page that include jQuery (for example), because 10% of this site uses it.
I take on this combination of the two. If I use the code for about 50% of the site or more, I include it in the "main" file. If the code is small (less than 5 kb or 10 kb), I include it in the main file. Otherwise, I split it into separate files.
All this reason is to improve user experience. You can make gigantic brute force and load all css and JS in 2 corresponding files for each page load (of course, this will be cached). But if the landing page does not require 50% of this code, you slow down the page with the greatest impact without extra effort.
And therefore, I believe that the best solution to this problem is to analyze the situation in a person. They can look for duplicates and abstractions. They can look at the needs of the page / site and determine the best scenario. If you do not want your program to do this (which would be difficult), this will not give the best result (but again, there is a difference between good and good enough) ...
What is my $ 0.02 anyway ...
source share