Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving a large CSS file

Tags:

css

I have a large minified CSS file at around 50k, this is referenced by about 30 pages.

Would separating the CSS into one base file with separate CSS files for each page significantly reduce load time, or is serving one large file practically the same? Thank you.

like image 479
David542 Avatar asked Feb 22 '23 19:02

David542


2 Answers

I'm not entirely sure what you mean, but serving one large file and caching it properly is definitely the way to go - ideally, that will cause only one HTTP request per client.

like image 156
Pekka Avatar answered Mar 07 '23 23:03

Pekka


50k really isn't that large - especially with most people's internet connections.

I'd keep the single file, because:

  1. You only need a single HTTP request to load the entire CSS
  2. CSS will be loaded for your entire website as soon as a single page is visited (which is nice for further browsing)

A similar topic would be the use of sprite sheets - which is essentially the same thing in that one large file containing multiple images is favourable over many smaller images nowadays.

like image 39
Marty Avatar answered Mar 07 '23 22:03

Marty