I use Speed Up to check the speed of my website and it gives some tips like: "Optimizing Cache". I found some info on yahoo.com like ExpiresDefault "access plus 10 years"
Should I put that rule in the .htaccess?
And another question, should I use that for my website? it's totally not static, it's a very complex browser game with dynamic pages. I found this link: http://www.askapache.com/hacking/speed-site-caching-cache-control.html
But when I cache the media files for one year, and then I update an image, it is not visible for the users for one year?
The html5 boilerplate project has extensive docs on setting up cache headers, and using the standard htaccess file which comes with the project on it's own can give you a great foundation in setting up cache headers correctly.
Cache headers define how long a user can download a file and expect the contents to be fresh. As such you should use short or no cache expiry for dynamic pages. Usually a short expiry for dynamic content is merely a means of managing server load - i.e. you only add short expiry when you're at the point of wanting/needing to reduce communication with your server.
For any url with a long cache expiry, when the contents change so should the url. so
/img/sprite.png
if you modify that file, make it:
/img/sprite_<x>.png
where x
is whatever you like - e.g. the date 20120326HHMM
If you use a build process, the above can be automated such that you don't have to think about it. That's also something that's covered at length in the html5 boilerplate docs.