Click to See Complete Forum and Search --> : Caching CSS files


callumd
08-20-2008, 06:08 AM
Hi,

Just have a few questions about CSS files on websites.

* Do web browsers only download the CSS files once, and then cache them when all other page requests from the site are made?
* If not, is there a way to command the browser to cache the CSS files (only download them once)?

I'm just thinking about website optimisation.

Thanks.

Declan1991
08-20-2008, 07:13 AM
They should be cached automatically. If not, you need to send an expires header with them. Exceptional performance from Yahoo! (http://developer.yahoo.com/performance/).

ray326
08-20-2008, 01:13 PM
Proper operation of the expires header is critical. Otherwise the browser will be make HEAD requests for all of its cached content (it may anyway) and in almost all cases that request is a huge part of the time taken for each conversation. In most cases the fastest load times will come from using an embedded style sheet inserted in the head of every page using some form of server side include.

callumd
08-20-2008, 09:48 PM
Thanks for the responses.

svidgen
08-28-2008, 09:25 PM
Yeah, really look into those Yahoo articles. In general, if you expect repeat visitors, separate your CSS and JavaScripts and set an expires header. If your site is a one-time-visit-single-pageview kind of site, you should really try putting all your CSS and JavaScript inline.

It's probably a good idea to send expires/cache-control headers for images in either case, since they're always external files.