Optimising website loading times - 5 minutes with Apache
I've come across a couple of very cool tips to decrease the loading time of webpages to the browser using Apache 2. They only take a few minutes to do and make your pages up to 50% quicker to load, which is never a bad thing. They also decrease the traffic between your users and your server.
These instructions are for Apache 2.2, they work equally well for earlier versions but you'll have to work out your own ways of enabling the modules (step 1)
1) Enable three module - mod_deflate, mod_expires and mod_headers
cd /etc/apache2/mods-enabled
ln -s ../mods-available/deflate.conf
ln -s ../mods-available/deflate.load
ln -s ../mods-available/headers.load
ln -s ../mods-available/expires.load
(any file exists errors mean they are already installed so don't worry)
2) Open your httpd.conf file
cd ../
vi httpd.conf
3) Add in the rules
(press i to enable the insert function)
copy and paste this lot:
ExpiresActive On
ExpiresDefault "access plus 300 seconds"
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/javascript "access plus 1 day"
ExpiresByType application/x-javascript "access plus 1 day"
ExpiresByType ext/x-js "access plus 1 day"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 day"
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript ext/x-js application/x-javascript
Press ESC
type :wq!
4) Restart apache
/etc/init.d/apache2 reload
Explanation
ExpiresActive On
ExpiresDefault "access plus 300 seconds"
This turns on the Expire module - this tells browsers when they should next look for a new version of a file. For static content like images this can be a long time, for files that are likely to change often this should be a shorter time. Default set as 5 minutes.
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/javascript "access plus 1 day
.... and so on
For each file type (MIME type is the technical term) we can fine tune the rules. 1 day for text, js and html files, 1 months for images and so on. You can set these to what ever you wish or remove/add as you please
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript ext/x-js application/x-javascript
Turn on the Deflate module - this sliently compressess the output specified in the line below - bit like when you use Zipping up to send large files to someone via email. All browsers decompress the output files without any trouble.
The text files are the ones targeted as they tend to be the most compressable - between 50% and 80%.
Conclusion
So there we have it - a very quick and simple way to make web pages quicker to load. It also makes Google love you that little bit more when its Bots are crawling your site, and that's never a bad thing.

Loading...
Thanks for dropping by and browsing our website. We hope you found something to interest you amongst all the geekness and techy speak.