S
S
SeiLove2015-06-24 16:34:05
css
SeiLove, 2015-06-24 16:34:05

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

8 answer(s)
D
Denis Ineshin, 2015-06-24
@SeiLove

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.

M
Maxim Timofeev, 2015-06-24
@webinar

If it's completely different css everywhere, then do:
1 common
and on each page in the header

<style>
ваш код уникальный для каждой страницы
</style>

But in practice I use 1 css and sometimes I include css files of various widgets and plugins. I can’t even imagine what kind of project you have there, in which each page has different css, and even in such a volume that you need to share it.

S
Sergey, 2015-06-24
@TsarS

So minify one file and it will load once

I
Igor Pushkarsky, 2015-06-24
@RainMEN

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.

G
Gluck Virtualen, 2015-06-24
@gluck59

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.

E
entermix, 2015-06-24
@entermix

>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?

D
Dmitri Sinitsa, 2015-06-24
@unabl4

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.

P
Pavel, 2015-06-24
@mrusklon

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 question

Ask a Question

731 491 924 answers to any question