Speeding Up Wordpress With Mod_headers and Mod_expires

Status
Not open for further replies.

mneylon

Administrator
Staff member
I've been experimenting with some tweaks to Apache / .htaccess to speed up some Wordpress powered sites, though the same techniques could be used with pretty much any site.

If you use Pingdom's tools to analyse your site's speed you'll probably get a few warnings about caching, so, if your site is on a server that has two Apache modules:
mod_headers
mod_expires
you can tweak your .htaccess to take advantage of some caching.

Just add the following into your .htaccess and use the comments so that it doesn't get overwritten by any other plugins that might write to .htaccess (most seem to respect comments)

Code:
## SET BROWSER CACHING ##

<ifModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</ifModule>

<ifModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|js|css|ico|swf)$">
Header set Expires "access plus 1 year"
</FilesMatch>

# 2 DAYS
<FilesMatch "\.(xml|txt)$">
Header set Expires "access plus 2 days"
</FilesMatch>

# 2 HOURS
<FilesMatch "\.(html|htm)$">
Header set Expires "access plus 2 hours"
</FilesMatch>
</ifModule>
## SET BROWSER CACHING ##

Using the
Code:
ifModule
in Apache means that your site won't break if the module isn't available - it'll break badly if you try to load it and it isn't there :)
 
K

Kieran

Guest
What site did you use this on. What was the impact overall on the site for you. Did speed improve the actual ranking as there is some talk that speed of loading has some 'small' impact on ranking.

Interesting to see how this worked.
 

mneylon

Administrator
Staff member
Kieran

It's more to do with overall tweaks etc., rather than ranking only .. One of the things that I wanted to see was better results in terms of the site speed tests, partially because a lot of our clients are using these criteria without fully understand them ..

So far I haven't see any massive impact, but this was part of a bigger exercise.
It's something that could probably work more effectively on a site where perceived performance is an issue

M
 
K

Kieran

Guest
Kieran

It's more to do with overall tweaks etc., rather than ranking only .. One of the things that I wanted to see was better results in terms of the site speed tests, partially because a lot of our clients are using these criteria without fully understand them ..

So far I haven't see any massive impact, but this was part of a bigger exercise.
It's something that could probably work more effectively on a site where perceived performance is an issue

M

Agree but speed irrespective of the ranking impact is nice to have and even though a slice of the ranking pie I think it is far from the most important...
 
Status
Not open for further replies.
Top