It is a best practice to combine CSS/JS files so that less requests need to be made to the site. How exactly to do it is not trivial, though. There are three extreme strategies:
- Don't combine anything. Good for caching, but lots of HTTP requests for users who have not cached the files.
- Combine every single file on the site into one. Also good for caching, and only a single request, but the file will be unnecessarily large and will contain a lot of unneeded stuff which slows down the browser and possibly leads to conflicts.
- Combine only the files which are needed to the current page. Only one request and no unneeded content, but horrible for caching - if you have 10 files, they can appear in a thousand possible combinations, so even adter your visitors have seen a page with files 1 and 2 and another with files 3 and 4, they would still have to download a new combined file for a page which has files 1, 2 and 3. (The situation gets even worse if we want to preserve the order of the files.)
The ideal solution is probably a combination of these three strategies (combine some files which are used on a lot of pages and include them everywhere, and combine the rest into a few files in a way that is hopefully identical with how it is done on other pages), but it is hard to find. You need to know what files are used on the site, which file is used on which page (or which type of page), how much visit each page type gets, how much of that comes from returning visitors... in short, it seems to be a huge pain to do manually. I'm looking for
- ideally, tools which are intelligent enough to do the optimization for you, or help with it.
- more realistically, tools which can make statistics of which CSS/js file is included on which page / how often those files are downloaded / how often two files are downloaded together.
- if there are no good tools for this, advice/strategies/best practices on how to do it manually