What is TTFB ?
TTFB is short form used for Time to first byte.As the name suggests it is total time taken for the first bytes of your web page to reach visitor browser.TTFB will be less if your server responds faster.There are many steps involved in this process.But we will concentrate on generation of web page by your server.The faster the page is generated the better is TTFB and load time of your website.
Testing your TTFB
You can use webpagetest.org to test your time to first byte.This site is used to test your website speed.It also gives you idea about your time to first byte.It gives different grades (A,B,C,D,E,F) depending upon your TTFB.Getting A or B in TTFB matrix is good.It also mentions your website TTFB in seconds.
Below is the image of my website speed test using webpagetest.org.You can see the time to first byte of my site in the image.
The second website which gives good amount of information about Time to first byte is bytecheck.com.Your time to first byte depends upon location of server and browser location.But it is better to have time to first byte less than 1 sec.Anything more than this is not considered good.
The faster the page is returned by your server the better is time to first byte.I will discuss all the techniques used to improve your TTFB.Improving TTFB is first step in website performance optimization.If your time to first byte is more your page load time can never be good.
In the first method I will be discussing on WordPress content management system only.But since most of the content management systems are similar it applies to others as well.Most of the content management systems have plugins and themes along with core to extend functionality provided by the core.
The other two optimization methods mentioned in this post are applicable to all websites.They are not dependent on any platform.So if you are not WordPress user then you can safely move to second point and third point.But you can try to make sense of first point in terms of your content management system.
WordPress plugin performance optimization
As mentioned above WordPress can be divided into three parts namely WordPress core,WordPress themes and WordPress plugins.So the time taken to generate a web page is you are using WordPress is combination of time taken by these three components.
Total load time = time taken by WordPress core + time taken by plugins + time taken by themes;
So analyzing these three components individually will be beneficial.So I thought to conduct a simple test.The aim was to find the component contributing the most in total load time.Reducing the component time consuming most time will eventually decrease total load time or page generation time.This will lead to faster TTFB (time to first byte).
To test this I used P3 plugin (plugin performance profiler).This plugin breaks down total load time into different components as mentioned above.I tested on my test website.The test website was using 15 plugins with no modification to WordPress core but some modification to WordPress theme.
Below is screen shot of the runs along with some important stats (no caching plugin was used)
Run with 15 plugins
The above test showed that major plugin load time was major contributor in total load time.The WordPress core and theme load time were pretty much negligible compared to plugin load time.So our major focus will be on reducing plugin load time.P3 plugin gives information about different plugins contribution to plugin load time.So plugins adding time to total plugin time can be figured out.
Based on this finding I deleted three plugins not very important for website but were contributing decently in plugin load time.After deleting the three plugins I performed the test again.This time total number of plugins was 12.
Run with 12 plugins
Some stats based on above test
|Component||Time taken(15 plugins)||Time taken(12 plugins)|
|WordPress Core||0.0511 secs||0.0474 sec|
|Theme||0.0347 secs||0.0378 sec|
|Plugin||0.2569 secs||0.0901 sec|
|Total Time||0.3427 secs||0.1753 sec|
I have not taken into account Profile overhead and margin of error in both case.So excluding them will have similar impact on both runs.The result might deviate to small extend.Below is small calculation based on above data.It shows impact of plugin on load time in both cases and performance gain by deleting plugins
- Impact of plugin on total run time (15 plugins)- .2569 / .3427 = 74 %
- Impact of plugin on total run time (12 plugins)- .0901 / .1753 = 51 %
- WordPress performance gain = (.3427 – .1753) = .1674 secs
- % Performance gain = (.1674/.3427) * 100 = 51 %
So you can see that percentage performance gain is as much as 51%.You will not always have this much performance gain.But on an average more than 20% gain can be expected.I have run similar tests for few times and in all cases performance gain was there.Performance gain will depend on number of total plugins you are using and number of plugins you are deleting.It will also depend on plugin you are deleting.
In my case I deleted three plugins out of which two plugins were not important and were taking decent load times.Some plugins are back end only and do not add up in load time for example my sitemap plugins.Deleting these plugins may not improve your performance to great extend.So you should run P3 test and see times taken by different plugin and delete those which are not important.
Conclusions based on above test
I have come up with some conclusions based on tests and data mentioned above
- WordPress is fast.It by no means can be termed as slow as criticized by many.WordPress core had good response time of 0.05 secs on an average.This is not bad at all.
- Theme load time may differ in your case.I have optimized my theme for performance.Later in the post I will cover WordPress theme optimization as well.Testing with default WordPress theme without any customization might lessen plugin load time.But after that also plugin load time will be major contributor in total load time.
- The three plugins deleted were not the worst ones in terms of load time.They are decent plugins best in their task.It is number of plugins that makes things worse.
Tips to use plugins properly
From above discussion it is clear that plugins should be used with care.Improper usage of plugins can hamper your website performance and time to first byte (TTFB).So I have listed some tips based on my own experience
- Installing plugins in your production site to test them.WordPress offers multiple plugins for same functionality.In my initial days I activated few of them to test on my production site before settling on one plugin.Each plugin does add some entries in wp_options table on activation.So your wp_options table becomes bulkier with time.This impact your query time.So it is better to use your test site for testing the plugins before using on production site.
- Using plugin for simple tasks.Example of simple task are adding social media codes,adding advertisement codes and adding Google Analytics code.These simple tasks can be taken care of easily without plugin usage.I have written several posts on adding these things on your website.It does not require coding skills.You can walk through the post and implement these on your website.Below are links to some of the posts
- There are some plugins which are not required every day.You need them periodically either monthly or fortnightly.Example of such plugins are
- Plugins used for cleaning and optimizing your database
- Plugins used for detecting broken links on your website
- Plugins for doing temporary tasks of periodic tasks
You should delete them after use.This is recommended but in case you do not want to install time and again then you can deactivate it after use.
Above can be achieved by a non technical user of WordPress as well.There is no need for modification of WordPress core and theme you are using. The next steps mentioned can be taken care of after above steps.
WordPress theme performance optimization
WordPress themes can be optimized for better performance by making small changes in theme files like header.php.All WordPress themes use database calls to retrieve general information like
- language_attributes() — language attributes
- bloginfo( ‘charset’ ) — character set
- bloginfo( ‘name’ ) and get_bloginfo( ‘name’, ‘display’ ) — name of the blog or website
- get_bloginfo( ‘description’) and get_bloginfo( ‘description’, ‘display’ ) — description of blog or website
- bloginfo( ‘pingback_url’ ) — ping back url of the site or blog
For each page request these database calls are made.This increases database hits (database server load) and thus slows down the website.As number of page request increases the database load increases and slows down the website.
You can follow below steps to remove these calls from your theme (taking header.php example)
- open your website in browser and view page source by right clicking on webpage and choosing view page source.
- open the header.php file in text editor
- search for the functions listed above in header.php file
- Look for the value in page source
- replace the function call in header.php with the value from page source (look below for example)
- replace all above functions with the corresponding value from page source.
Original Code in header.php file
<html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>" />
Corresponding value in Browser view source
<html lang="en-US" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
Modified code in header.php file
<html lang="en-US" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
We can use cache to improve time to first byte.If cache of a page exist then requested web page is loaded from cache itself.This reduces response time.The page will be catered fast.The reason is that all code mentioned above will be bypassed.Only the code required to locate the cached version of page will run.
There are many caching methods available.In case you are using VPS or dedicated server then I would suggest using Google PageSpeed.I have written a detailed post on ngx_pagespeed.I will not suggest using any WordPress caching plugin for VPS users or dedicated server users.ngx_pagespeed can be used for users of any content management system.
For shared hosting users it is better to use WordPress caching plugins.There are many caching plugins available.But most complete one is W3 Total Cache.This plugin has lot of options and is tough to configure for new users.So I have written a detailed post on W3 Total Cache configuration.
Using Free CDN
This is another method to improve your time to first byte.There are many Content Delivery networks.But I will like to discuss about CloudFlare free content delivery network.I have used this content delivery network myself.It is good way to improve your TTFB.
I have written detailed post on configuration of CloudFlare content delivery network.It is step by step tutorial.You can read the post and in parallel configure your site to use CloudFlare.Shared hosting users can also use CloudFlare free CDN.
I would suggest you to employ all the methods mentioned above.First solution should not be ignored.As it improves TTFB of not cached web page.If you are not taking care of first method then your not cached web page request time to first byte will be significantly higher.Using last two methods will help you decrease time to first byte TTFB of cached pages.
Consider sharing the post in case you found it useful