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.