Cache Images, CSS, Javascript and HTML On Your Server To Speedup Load Times

At Techie Buzz we use a cache server to serve up static content, it helps us reduce the load on the main server, however using a cache server in itself is not going to help speed up load time, you also need to make sure that the files are cached by the browser too.

Many webmasters do not do this, so here is something that will help speed up the load times for your website/blog.

You will need to edit the .htaccess file on your server, if you are not aware of what .htaccess does, you might find the Wikipedia article on Htaccess useful.

In addition to that, this .htaccess file must exist in the root directory of your website/blog.

   1: FileETag INode MTime Size
   3: <IfModule mod_deflate.c>
   4: <FilesMatch "\.(js|css)$">
   5: SetOutputFilter DEFLATE
   6: Header set Cache-Control "max-age=2419200, public"
   7: </FilesMatch>
   8: </IfModule>
  10: <IfModule mod_expires.c>
  11: ExpiresActive On
  12: ExpiresByType text/html "access plus 20 seconds"
  13: ExpiresByType image/gif "access plus 2 months"
  14: ExpiresByType image/jpeg "access plus 2 months"
  15: ExpiresByType image/png "access plus 2 months"
  16: ExpiresByType text/css "access plus 2 months"
  17: ExpiresByType image/ico "access plus 2 months"
  18: ExpiresByType text/javascript "access plus 2 months"
  19: ExpiresByType application/x-javascript "access plus 2 months"
  20: </IfModule>

You can easily change the amount of time you want each component to be cached for, however most of the cache time in the above code is best suited for most websites/blogs.

You can view a clean copy of the .htaccess file here or download the file here, this should definitely help speedup your load times for return visitors.

Published by

Keith Dsouza

I am the editor-in-chief and owner of Techie Buzz. I love coding and have contributed to several open source projects in the past. You can know more about me and my projects by visiting my Personal Website. I am also a social networking enthusiast and can be found active on twitter, you can follow Keith on twitter @keithdsouza. You can click on my name to visit my Google+ profile.