One of the problems that it seems I am always faced with when building a WordPress site is speed. Previously all my speed problems were directly related to my old host (Network Solutions), the latency for their shared hosting was atrocious.
So after building my site locally and testing it on a development domain I consistently find that multiple plugins, tons of server queries, and large content size will slow my site to a crawl, and as we all know, load time is disastrous to traffic. Hell, I wouldn’t even visit my old site because it took way too long to load.
Now, there are a ton of tutorials online that talk about different ways to speed up your WordPress site but as I like to keep my posts short and sweet I will just focus on two. Using .htaccess to add expires headers to content, and using Wp Super Cache to cache up pages.
Just in case though here is a list of ways that you can speed up your site, you will have to search for tutorials on these, or maybe I will cover some info on them later.
Short list of WordPress speed tips
- Use Css sprites for images (cuts down on http requests)
- Use a CDN (content delivery network) like Amazon S3
- Add expires headers to page content
- Gzip components (Just found out that Host Gator only does Gzip on dedicated servers…crap!)
- Move all javascript to the footer (wow this helps out a ton, unfortunately most plugins don’t do it.)
- Minify Javascript and Css (if you want to reduce the size of your css i love this tool)
- Delete any Plugins your not using
- Replace the header.php file with static elements removing PHP functions (controversial see here )
- Optimize database with phpmyadmin (super easy to do)
- Keep your images small or optimize them
- Reference your script libraries, like Jquery, through google source (more info)
Super Tip
Here is a great tip. If you want to see how may queries your site is making to the server and how long it takes for you site to load just paste my super awesome script into your functions.php file and when your logged in (and only when your logged in) you will see a count at the bottom left of your site.
[php]<br />
<?php<br />
if (is_user_logged_in()) {<br />
?><br />
<div id="speed-test" style="padding:10px;background:#F66;color:#fff;font-weight:bold; position:fixed;bottom:0;"><br />
<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.<br />
</div><br />
<?php } ?>[/php]
Now on to the .htaccess and Wp Super Cache
So i did a bunch of research on how to insert expires headers in side of you .htaccess file and the only thing that i found that would work with my host and on word press was the following.
[text]<br />
# Expire images header<br />
ExpiresActive On<br />
ExpiresDefault A0<br />
ExpiresByType image/gif A2592000<br />
ExpiresByType image/png A2592000<br />
ExpiresByType image/jpg A2592000<br />
ExpiresByType image/jpeg A2592000<br />
ExpiresByType image/ico A2592000<br />
ExpiresByType text/css A2592000<br />
ExpiresByType text/javascript A2592000[/text]
Just upload the .htaccess file to the website directory where WordPress is installed and you should see that items now have expires headers by using a firefox plugin called Yslow.
That was the hard part, the easy part is just installing Wp Super Cache and configuring some settings. Wp super cache will do the rest and you should see results on Yslow right away!