I must say I didn’t particularly pay attention to caching/server performance before, I have always (wrongly) thought the stronger the hardware the less issues one is going to encounter, but since I got introduced to nginx… I am blown away.
WordPress 3.0 does some rather (positively) aggressive caching itself, but with nginx behind it we have witnessed our page-load times to be up to 4× faster!
Chasing YSlow and PageSpeed rankings we needed to update the nginx expires headers condition to cater for our plugins’ static files (CSS and JS). Again, not that I have ever particularly noticed but not all plugins reference the latest version of their CSS’ the same way. One comes across:
- .css
- .css?1278974243 (UNIX timestamp)
- .css?ver=2 (variable followed by an integer ONLY)
- .css?ver=absd234 (variable followed by mixed characters)
- .css?version=2.2alpha (variable of any length followed by mixed characters including “.”)
You see where I’m going with this. So after picking up a useful rewrite from StackOverflow – which catered beautifully for Redmine, we were faced with variations in WP we didn’t encounter originally and the script didn’t cover either. Digging deeper into the issue we came up with this, which now fully caches all 0f the above mentioned variations:
if ($request_uri ~* \.(ico|css|js|gif|jpe?g|png|pdf|rar|swf|zip)(\?[0-9]+)?.*$) {
expires 1M;
break;
}
This should go into your config file in “/etc/nginx/sites-available/whatever-your-config-file-is-called”.
Hope it helps