In the context of improving overall site performance (loading and rendering speed), there seems to be a contradiction between the following two best practices:
Just remove the CSS that you need for the page you're viewing. (Because too many CSS rules cause slow rendering)
Always reduce CSS and merge it into a single file. (Since more requests mean slower page loading)
Now I will say that I decided to follow rule 1.
The following issues appear:
What if 2 pages use the same set of CSS rules?
In this case, I need to put these rules in a separate file and link to this file from both pages.
However, if I have a lot of these “general rules,” I may end up with a lot of separate files from each page, and thus a violation of rule 2.
For example, page A may depend on CSS 1 and 2, while pages B and C depend on CSS 2, and page D depends on CSS 1.
In this case, it is impossible to have exactly one CSS per page or even several CSS per page, as some pages will need to share some CSS files with other pages.
But we cannot solve this problem by combining all the CSS for each page into a separate CSS file on the page?
We could, but it would create other problems.
CSS, , , , , CSS .
CSS , , CSS .
, CSS , , , .
, ?
:
1. CSS, .
, / CSS .
, , , :
CSS, , , .
CSS , , , , , , .
?