Answer the question
In order to leave comments, you need to log in
1 css for the whole site or different for each page?
Good afternoon everyone! We have been discussing this issue with a friend for a long time, however, both are newcomers and we cannot come to a final decision. Let's describe a typical situation:
Let's say there is a site with a large number of unique pages with different elements. The design was originally built in such a way that you can’t cheat a little and you won’t save on code.
And the question arises: Should I write a single css for the entire site for all pages, or is it better to write my own for each page? On the one hand, the less css the faster it loads? On the other hand... css is cached, which means that loading a large style 1 time will be better?
Answer the question
In order to leave comments, you need to log in
Don't worry about this topic. One CSS file for the entire site is enough. If you glue all the styles into one file, compress it into a line, and then the server will also compress it with gzip. That is sufficient optimization.
If it's completely different css everywhere, then do:
1 common
and on each page in the header
<style>
ваш код уникальный для каждой страницы
</style>
It makes no sense to divide the file, only if it is on different sections of the site.
1. Website.
2. Admin.
3.PDF.
4. Printable.
5. Mobile version of the site.
6. The left hand of the designer.
7. The designer's right hand.
There is nothing to discuss here.
Use a file manager to enter a directory with thousands of files with a total weight of several megs. Copy them somewhere, mark the time.
Go to another directory with a couple of files with the same weight. Copy, note the time.
Is the question gone? Congratulations.
>On the other hand... css is cached, which means that loading a large style once would be better?
But why download something that you might not need?
Depends on the final size of the resulting file. If there is something about 50-100 kb (well, purely empirically) or less - score. Plus, do not forget that you can apply compression (uglifier), gzip, etc., which is configured, in principle, very quickly.
Even for a 2G connection, this is nothing, and for a web browser, performance never rests on css (even if you use crooked selectors, many levels of nesting, and other bad things).
Although, ideally, of course, it is better to have separate, kmk. But this should be done last.
Pro tip :-) : It's better to pay close attention to javascript, especially third-party ones. All front-end brakes tend to come out of there.
all answers are good BUT, how many pages on the site? It is not the file size that decides, but the number of requests, css is a small file, even for 100500 pages it is 1% or even less of the entire site.
I think if there are up to 10 pages, then let the file be one. If more then share.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question