CSS and JavaScript: More Files or Less?

If you do much reading about web optimization, you will have heard people say that you should cram all your CSS into a single large file, and all the JavaScript into another, in order to save on loading times.

80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages. (Yahoo Developer Network)

In other places, you will be told that you should separate your CSS into multiple files to make it easier to manage. One for layout, one for typography, one for colors…

Which do you think is a better idea? Personally, I prefer quick loading times. Your users will thank you for faster pages; they don’t care if it’s easy to edit parts of your site or not. Generally I prefer to put all of the main CSS into one file, but on pages that require a large amount of unique styles, I include a separate file with the page-specific styles.

  • http://www.isuckatdesign.com Heather

    I like to work with multiple CSS in the building process, but when it comes to launch time, I combine them into one, adding comments to ease updating later.

  • http://www.ruelicke.net Marco Ruelicke.net

    I use a single CSS file, even during the building process. Imo it makes things a bit easier to use one single file.

    The only time I have two CSS files is when I have to add some IE only fixes. Those fixes end up in a second file which is only loaded if a IE user visits the site.

  • http://compsci.ca/blog Tony

    There’s no reason why you can’t have the best of both worlds. Develop in multiple files, but have them merged for live copy. Having this added to a deployment script will make this happen automagically.Besides cutting down on the number of files, various optimizations could also be run — such as compression scripts for CSS and especially JavaScript.

  • http://www.webmaster-source.com Matt

    @Heather and @Tony, excellent suggestion.

    @Marco, I use a similar method.