WordPress knowledge sharing

What is TTFB (first byte time)? How to reduce TTFB?

Websites that have tested pagespeed insights will encounter the prompt "Reduce initial server response time". The initial server response time can affect the page loading time and performance indicators, such as maximum content rendering, core web life indicators, and PageSpeed scores. that is TTFB The smaller the better.

When troubleshooting websites that open slowly, First byte time (TTFB) is an important indicator. If you are looking for effective ways to reduce the TTFB time of WordPress websites and servers, this article can provide you with some valuable directions and ideas.

What is TTFB (first byte time)?

Full name of TTFB: Time to First Byte. What are you waiting for? In addition to the time it takes to wait for the server to deliver the response, there is also a delay in the round trip to the server.

It refers to the time from the time when the visitor sends an HTTP request (such as opening a domain name) to the time when the user's browser receives the first byte. The process is basically like this: the visitor sends an access request and locates the CDN node or host server from the domain name resolution. Read the website data and return it to the user's browser until the page content is loaded.

In short, TTFB is the time from the moment you open a web page to the moment when the page is presented. As the name implies, it is a period of "waiting".

The following is the action of the server: a content management system (CMS) such as WordPress. The server needs to execute all static (text, pictures, videos) and dynamic content (php files, databases) of the page. PHP computing and reading databases are time-consuming. The PHP service loads the MySQL database of the website, obtains the content, calculates the HTML output, and returns it to the website visitor.

TTFB includes three sections:

1. Time when the HTTP request was sent

TTFB starts when a visitor sends an HTTP request. The time the server receives the request mainly depends on the DNS lookup time, the user's network speed, the geographical distance between the server and the server, and possible interruptions in the connection.

2. Time to process the request

When the server receives the request, it will process the request and respond. It includes starting the php process, entering the database to search and call, running the js script, css style sheet, and communicating with other network systems.

3. Time required for the server to send the first byte of the response back to the browser

The server sends the response to the user. It depends on the network speed of the server and the user.

The above steps all take time. If the optimization is not good, the TTFB of the website will be very high, such as more than 10 seconds or more.

The longer it takes to send a request to the server, process the request, and send the processed data back to the user's browser, the longer it takes to display the web page. We call it TTFB is too large and needs optimization.

But it is not necessarily because the host is slow. It is also possible that too many plug-ins have been installed (I have seen 50+plug-ins installed, and more to say). The cache system is not used, and the PHP 5.6 version with low performance has been used (except for special cases).

We can't manage the users. We can only find ways to optimize the server and CDN (manage ourselves).

How normal is TTFB?

Google recommends that the TTFB be less than 200 ms. Lighthouse thinks that the request is unqualified after 600 milliseconds.

If the TTFB is longer than 1 second or even larger, it means that there are some performance bottlenecks in the server, and the problem needs to be found and optimized.

As shown in the figure, Weiss Notes TTFB of about 500 ms.

 The TTFB of Weieis' notes is more than 500ms

Measure TTFB value

Generally, you can use the Gtmetrix website to test the TTFB value of your website and use it as a reference.

Interested please see Detailed introduction to GTmetrix website performance test To understand the specific test methods.

Many foreign websites can test the TTFB value, and it is OK to know that there is such a thing.

Select [Hong Kong, China] node test for domestic websites; Select [Canada] or [United States] node test for foreign websites.

Causes of high TTFB

WordPress website has several factors that affect the time of the first byte: DNS response time, network latency, server configuration and performance, and dynamic content.

We use the following 9 methods to reduce TTFB (first byte time) in WordPress.

Use a fast network host

Using a stable and fast host server will greatly reduce TTFB.

For example, most of the visits to Weiaisi's notes are in China, so we choose Tencent ECS As the basic platform of the website.

Selecting a host node with more visitors, whose physical location is closer to the user's location, will effectively reduce TTFB.

In addition, there are also options in China AliCloud server , also have excellent quality.

While most users of foreign trade websites and cross-border e-commerce websites are located in the United States, it is recommended to host the websites in the United States. If most users are in Europe, they should be hosted on European nodes. If there are both American and European customers, they should be placed at the American node.

Suggested choice of foreign trade B2B website and cross-border e-commerce website Siteground Hostinger Virtual host and other platforms. 2C suggested choice of website Vultr Host station establishment.

The host server is very important, which is the cornerstone of building a website. If the cornerstone is unstable and has poor performance, you will get twice the result no matter how you optimize it.

Use CDN

CDN can help websites send static content of websites to users faster through cache server nodes all over the world.

For example, if your host is placed on the American host, when European users visit, they will call the website content from the cache server of the nearby Amsterdam CDN node in the Netherlands, without visiting your American host, which saves the round trip time from Europe to the United States. It effectively reduces the network latency between the website host and visitors.

For more information, see Does ECS still use CDN acceleration? What website needs CDN?

Advanced DNS Service

Ordinary DNS does not provide advanced DNS functions, that is to say, DNS services provided by domain name providers are free, while paid DNS packages can provide more DNS resolver nodes, making DNS resolution faster. Good DNS providers will use DNS server networks all over the world to answer DNS queries with low latency and reduce TTFB.

Wei Aisi's notes have been purchased Tencent Cloud DNS Resolution Package , which is faster than the normal free DNS resolution to answer access requests.

If you are interested, please move Difference and connection between DNS resolution and CDN acceleration

Enable cache

A simple way to reduce TTFB is to add a cache in the WordPress website. Caching can help reduce TTFB by reducing server processing time.

For the server, enable memcached or redis It is necessary. For the virtual host, install a WordPress cache plug-in.

Related reading: Mistaken Ideas and Correct Methods of Installing Memcached on Pagoda Panels

Detailed Graphic and Text Tutorial of WP Rocket Plug in Installation, Deployment and Settings

WordPress cache acceleration optimization plug-in WP Fastest Cache (supporting Chinese)

Detailed Guide for Installation and Configuration of WordPress Cache Acceleration Plug in W3 Total Cache

Tutorial of LiteSpeed cache plug-in installation and setting

WP Super Cache Cache Plug in Optimization Setting Process

SG Optimizer plug-in accelerates website speed

Enable GZIP compression

After GZIP compression is enabled, the size of HTML, CSS and JS files will be greatly reduced, the page resources will be downloaded faster, and the TTFB will be reduced.

ECS usage Construction of pagoda panel station The pagoda panel enables GZIP compression by default.

Foreign virtual hosts support GZIP by default, so we don't need to worry about it.

Don't know if your host supports Gzip? Please see Various methods for detecting whether Gzip compression of web pages is successful

Optimize database

Common database garbage, such as article revisions, deleted and garbage comments, and temporary files created by plug-ins, will affect the server response time.

It is strongly recommended to optimize the database size and clean up garbage regularly.

You can regularly use the following plug-ins to clean up database garbage: WP-Optimize Optimize Database Advanced Database Cleaner

Popular The wp rocket plug-in comes with the function of cleaning the database , and one plug-in can be saved.

Timely update of WordPress, plug-ins and themes

WordPress program, plug-in and theme updates will affect the query of code running to the database or affect the running efficiency of PHP code.

Please check the plug-ins and themes regularly. It is recommended to keep only the plug-ins and themes used and delete the ones not used.

Choosing the right theme and plug-in is also a very skillful thing. The code quality of plug-ins and themes will affect TTFB. Some plug-ins will run in the background, and the website will be checked at intervals. Some topic codes query the database too many times, and TTFB will be added.

In general, it is necessary to update WordPress, plug-ins and themes regularly.

Reduce database queries

WordPress reads the database several times, and too many queries will affect TTFB.

Can be installed WordPress check detection plug-in Query Monitor , find out which plug-ins, themes or settings are affecting the page speed of the website.

PHP version

The performance of PHP 7.4 is much faster than that of all previous versions. Using the new version can effectively improve TTFB.

Due to special circumstances, some old programs only support PHP 5.6, so you can't enjoy the speed brought by PHP 7.4.

Many plug-ins and themes do not support PHP 8.0, so PHP 7.4 is a suitable choice.

summary

After using the above methods on the website, it can effectively reduce and improve the TTFB, which will greatly improve the website performance.

As the website opens faster, the visitor experience will be effectively improved, which is our ultimate goal.

Like( one )
Article name: What is TTFB (first byte time)? How to reduce TTFB
Article link: https://www.vpsss.net/28514.html
Copyright notice: The resources of this website are only for personal learning and exchange, and are not allowed to be reproduced and used for commercial purposes, otherwise, legal issues will be borne by yourself.
The copyright of the pictures belongs to their respective creators, and the picture watermark is for the purpose of preventing unscrupulous people from stealing the fruits of labor.