Categories
WordPress

Speed up your WordPress

If you use, as me a shared hosting for your blog, maybe you noticed (normally) that the speed of your WP installation really sucks.

There’s few reasons why your WP is so slow.

  • Sharing resources with other sites (cpu, memory, badnwidth…)
  • Too many posts or comments (DB issues).
  • Lot of visitors

Depends to your situation maybe you need to use some solutions or others. In my case to use a dedicated server is not an option since I don’t have budget for it, then I need to find other solutions.

I will explain what I have changed:

Data Base

WP makes lot of queries to the DB, this reduces the response time of your site a lot.

This is my blog  (deambulando.com 5000 unique visitors day, 11.500 comments, 2300 posts) without any improvement:

Generated in  2.466 seconds. Made 67 queries to database

After the tips:

Generated in 0.834 seconds. Made 20 queries to database and 19 cached queries

To decrease this we can use this 3 plugins that I propose. Each of them has a different function an is important to understand what does each of them.

  • DB-Cache, with this plugin every single query to your DB will be stored in the HD of your hosting during a certain time. This makes that your DB has lot less stress and normally (depends your hosting) it will increase the speed of WP. Be aware that also can make your WP slower in certain situations (lot of HD traffic) and only use it if you don’t have any other option (like I have) .
  • WP Widget Cache, this one I really like. Uses an individual cache for each of your widgets so you can specify time to expire or action that would make the cache expire, really useful.
  • WP Super Cache, this is one of the most famous WP plugins, generates static html files (with expire date) from your dynamic WP. It uses lot of HD access and creates lot of files, so be careful.

After using some of the previous plugins, it is also important to keep your DB optimized. For this action I use the plugin WP-Optmize, that also can help you erasing the spam and the post revisions. I do this action almost every week or more often it depends.

Also if you have just a bit of knowledge of PHP or HTML you can make some changes in your template to increase the speed. The idea is to replace in the header for example where they made a call to a function, when it could be easily an static text. This is done like this, since the templates they should work at any installation and be aware that after doing what I’m telling you would not be like this and not dynamic anymore.

Example of replace:





for





Using this tip I decreased the queries from 30 to 27 in the same template same page, is not so much but it counts.

File access

Other trouble that you can have is the hotlinking. This causes stress in your server and use of the unauthorized bandwidth. One simple/effective way of controlling this is using the .htaccess file.

You can add an instruction like this to prevent from certain files:

.htaccess file:

#NO HOTLINKING
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www.)?YOURDOMAINNAME.com($|/) [NC]
RewriteRule .(gif|jpg|jpeg|png|mp3|mpg|avi|mov)$ - [F,NC]

Robots

Finally and to end this document I want to talk about “the bots”. Normally they are friendly and they help to have your content updated in the search engines. But if they go to often to your site that increases the traffic of your site.

To control this and which section they are able to “see” we need to have a Robots.txt file.

This is my robots.txt file:

User-agent: *
Crawl-Delay: 3600
Allow: /wp-content/uploads/*.gif
Allow: /wp-content/uploads/*.png
Allow: /wp-content/uploads/*.jpg
Disallow: /wp-
Disallow: /search
Disallow: /?s=
Disallow: /feed
Disallow: /comments/feed
Disallow: /author/
Disallow: /useronline/
Allow: /feed/$
Disallow: /*/feed/$
Disallow: /*/feed/rss/$
Disallow: /*/trackback/$
Disallow: /*/*/feed/$
Disallow: /*/*/feed/rss/$
Disallow: /*/*/trackback/$
Disallow: /*/*/*/feed/$
Disallow: /*/*/*/feed/rss/$
Disallow: /*/*/*/trackback/$

As you can see I don’t allow the bot to many places and also I put a crawl delay to say them come slower. For google this doesn’t work and you need to do it in your webmaster tools.

That’s all, for any question post, or use the forum please.