Serving a large CSS file
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 开发者_JAVA技巧you.
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.
50k really isn't that large - especially with most people's internet connections.
I'd keep the single file, because:
- You only need a single HTTP request to load the entire CSS
- 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.
Assuming that the majority of the css is being used by each page the ideal way to serve it is as a large file. HTTP Requests take time so having several small files requested by a page takes a while to load, not to mention the cap on the number of simultaneous connections. Second of all, and even more importantly, proper caching means that they only need to download the entire file once.
Yes separating them for each page would reduce the load time for each page since each page would only be pulling the css that it needs.
精彩评论