Google has created a campaign to make the web faster, and a corresponding website to help web admins to make it so. Speed is a big factor in customer perception of your site. Google has conditioned the masses to expect instant page loads and sites that take even 2-3 seconds to load will only be tollerated for so long. Couple this with pages become more dynamic and resource hungry everyday.
Here are some changes I’ve made to my web server to speed things up.
Compress files with mod_deflate (dumb name)
I already had a declaration in my
http.conf file for
LoadModule deflate_module modules/mod_deflate.so. So I created a rule in one of my virtual host files for
<Location /> AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml </Location>
That should effectively compress all html, plain, xml, and css files.
I want to set an expiration of one month in the future for all my cache-able content. Apache mod_expires will do the job nicely. Again in my httpd.conf file I had and entry for
LoadModule expires_module modules/mod_expires.so.
Then in I created a file
conf.d/expires.conf and placed the following code in there.
This will enable the expires module, then set the default expires to ‘access’ or ‘right now’. You can tweak it to your liking, but the following types of content have expiration date of 1 month from the time the browsers first sees the content.
You want to scale your JPEG images down to as small as possible. Some of my images were way too big and I could shave huge amounts of data with virtually no image loss by reducing my JPG images.
I created a script that uses the jpegtran program found on Linux machines. I created the following bash script
optimize.sh that will take a folder of JPG images, copy them to another folder called
new-opt-jpegs and then compress them.
mkdir new-opt-jpegs for filename in $( ls $1/ ) do jpegtran -opt $1/$filename > new-opt-jpegs/$filename done;
You would use the script like optimize.sh images/`. This will take all the JPGs in ‘images’, compress them, then copy them to a folder called ‘new-opt-jpegs’.
Did this help you out? It took me a few days to piece together all this information together, I hope this saves you some time (who knows, maybe the future me will be thankful I wrote this down). Let me know your thoughts. firstname.lastname@example.org