Category Archives: Apache

Quick and easy way to make websites load faster

This is just a quick post to quickly get you to improve your website’s speed if you are running an Apache web server.

Create a .htaccess file (if one isn’t already present) and add the following lines at the end of the file:

# GZip
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css

# Setting longer cache time
ExpiresActive On
ExpiresByType text/css “now plus 1 month”
ExpiresByType text/javascript “now plus 1 month”
ExpiresByType image/gif “now plus 1 month”
ExpiresByType image/png “now plus 1 month”
ExpiresByType image/jpeg “now plus 1 month”
ExpiresByType image/x-icon “now plus 1 month”

The first statement enables compression for HTML, plain text files, XML, JavaScript and CSS. Enabling compression means that the data is compressed before being transmitted. Less data to move means things can move along a lot quicker.

The second set of statements enable caching by file types, namely on CSS, JavaScript, GIF, JPG and ICO. Now I’m using a cache expiry date of one month, but you can use anything that suits you.

For example, if you make a lot of changes to the CSS and images, you might prefer files to expire after a day, in which case you can change it to:

ExpiresByType text/css "now plus 1 day"

The ExpiresByType can take in a number of keywords like: years, months, weeks, days, hours, etc. For more info, check out Alternative Interval Syntax for ExpiresByType.

If you have anything to add, feel free to drop it in the comments and I’ll update the post.

Flattr this!

Block access to .htaccess

Before I answer the ‘how’, let me answer the ‘why’.

.htaccess, now a days, plays a major role. It lets you re-write URLs, redirect traffic, and if you are really good with it, point people to different scripts on your website. It is also an excellent way to cloak your web space structure.

The problem occurs if someone is able to have a look at your .htaccess file and see how things are processed at the ‘back stage’. Or the reason could be that you have written a state-of-an-art .htaccess file and want those 16 year olds to stay away from it.

Just place this at the top of your .htaccess file and you can sleep peacefully, once again 😉

Flattr this!