Table of Content

11 Tips for Magento TTFB Optimization (Updated 2024)

Magento 2 Time to First Byte

TTFB stands for time to first byte. This metric reflects how fast a user starts to receive the content after they’ve opened a website. Server response time is one of the crucial web performance indicators which contributes to reaching a better PageSpeed Insights score. Store owners know perfectly well why they should aspire to the highest grade: to enhance both Google rankings and the customer experience.

Reducing TTFB is a complex task. There could be numerous reasons affecting it linked to a web server, caching strategy, database configuration, and, surely, the code itself. In this article, we’ll discuss profiling tools, define major issues, and find ways to improve TTFB for Magento stores.

The Good, the Bad, and the Ugly TTFB

When a person opens a website, 200+ database queries, API calls, PHP operations, and other processes start immediately. Put simply, three major tasks together make time to first byte:

  • a request is sent to the server;
  • the request is processing; a response is generating;
  • the response is fetched to the client.

As soon as the user gets the very first byte of content, the “stopwatch” stops.

So, what is good TTFB? Some time ago, Google recommended aiming for 200 milliseconds (or 0.2 seconds) or less. As of now (January 2024), the requirement is less strict: if the Magento server response time is , it’s still displayed in the “Passed audits” section of PageSpeed Insights.
But once time goes above that mark, it’s a red flag: you’ll see the metric in the “Opportunities” section. So, it’s time to start improving your site’s loading speed since it influences other crucial metrics. You also have to take care of the user experience: if customers wait even an extra second, this negatively affects conversions.

TTFB thresholds

In the meantime, some settings can increase TTFB to an unbelievable size. In our experience, the worst seen time to first byte was 21 seconds! The reason behind such horrendous Magento server response time was the server making queries to another one to download images every time somebody opened that website.

Of course, cases like this are extremely rare, but even a one-second delay does substantial harm. Google states as page load time increases from 1 to 3 seconds. That’s why it’s essential to find and get rid of pitfalls hindering your store from faster loading.

TTFB and Core Web Vitals

What about TTFB’s effects on your store’s performance score? Let’s turn to Google PageSpeed Insights again. The report advises the following: “Keep the server response time for the main document short because all other requests depend on it (FCP, LCP).”

You are probably aware of FCP, LCP, and a couple of other Web Vitals. These are indicators used by Google to measure web performance from the UX perspective. The approach considers several aspects that hugely influence the user experience: loading, interactivity, and visual stability.

  • First Contentful Paint (FCP) is the amount of time between the start of page loading and the appearance of any piece of content on the screen: logo, text, image, or anything else.
  • Largest Contentful Paint (LCP) is the time needed for the largest above-the-fold image, text, or video to render. It's also one of Core Web Vitals (find more on in a dedicated guide).

Both metrics reflect loading performance. Among other parameters, they depend on the server responsiveness: server latency leads to worse web vitals scores. When they’re calculated, TTFB is included. The more TTFB takes, the more likely LCP will fail the Core Web Vitals Assessment.

The screenshot below illustrates the issue. TTFB is 1,5 seconds, then loading and rendering site resources (JS, fonts, styles, and the content itself) block FCP and LCP for the rest of the time. TTFB is not the only problem here, but it affects the final figures. Respectively, its optimization leads to improvements in other essential user-centric indicators.

How to Measure TTFB

There are a bunch of ways to check the time to first byte on your online Magento website:

  • Lab options like Lighthouse, Gtmetrix, or Webpagetest (lab tools make assessments in ideal conditions: a particular server and good internet connection);
  • Google PageSpeed Insights (provides lab as well as field data, which is collected from real users);
  • Field options: the Chrome User Experience Report or Google Search Console;
  • Browsers can also display TTFB;
  • Developers evaluate TTFB with the help of profilers as the most precise tools. They measure the script processing speed and show how much time each operation took, giving insights into what to fix. We’ll talk about profilers further.

We recommend taking measurements using a few instruments and comparing reports to obtain a comprehensive idea of your server responsiveness. When it comes to eCommerce sites, it’s obligatory to test the homepage, category, product pages, cart, and checkout.
Besides this, it’s important to assess TTFB with server caching (block and full-page cache) turned off to get objective information.

What Slows Down TTFB on Magento?

Slow Magento 2 response time is more than a widespread issue for online stores. Let’s define the most common contributors:

  • Unoptimized code: heavy PHP logic, slow and/or excessive MySQL queries, unnecessary code, absence of caching on the code level.
  • Unoptimized web server: poor configuration, disabled compression (for instance, Gzip), non-optimal server location.
  • Absence of backend caching: without it, a store can’t cache some requests, chunks of the code, code logs, and HTML files in advance to retrieve them faster.
  • Unoptimized database: poor queries or caching configuration, absence of indexes, and so on.

There can be more reasons for the time to first byte increase. Let’s discuss how you can find such problems.

How to Find Bottlenecks Affecting TTFB

The first step to reducing Magento 2 server response time efficiently is conducting a profound audit. Here different profilers come in handy as a developer has to check endless code lines in terms of execution time.

There are two groups of profilers:

a) Magento modules: Magento in-built profiler, Mirasvit Profiler, and MGT Developer Toolbar. All these tools examine basic queries and can’t boast great detailing.

Magento profiler for finding TTFB bottlenecks

b) External tools: XHProf and Xdebug Profiler. Roughly, via Magento modules, we’ll see 100 calls, while these instruments showcase 1 000 000. There are entire stack traces with all calls. Most of them take fractions of milliseconds, and a developer skips them, concentrating and studying inadequately long ones.

We’ve covered the matter of profiling deeper in our guide.

How to Reduce Server Response Time on Magento 2: Top 4 Steps

TTFB optimization contains multiple subtasks. The good news is, most of the measures mentioned below are part of the general Magento website speed optimization.

1. PHP Optimization

  • The very first step for a Magento store to improve server response time is to rethink slow PHP code chunks so that they execute faster as well as reduce the overall number of operations.
  • Reduce the work with files. For instance, many modules have a debug mode that is accountable for logging. Turn it off to avoid the overproduction of log files.
  • Be careful when using PHP modules like Xdebug Profiler. It’s able to slow down the whole website even if it isn’t in use but enabled (we’ve seen a 5x slowdown). It’s vital to keep it disabled when your website is live.
  • Update PHP to the latest version and configure it in line with the platform’s requirements.

2. Web Server Optimization

  • Implement HTTP/2. Many Magento stores still use HTTP/1. But unlike it, HTTP/2 is able to handle requests not one by one but in parallel. Moreover, developers can prioritize more important queries over others.
  • Leverage browser caching to keep static content (fonts, images) in users’ browsers for a longer period (for instance, a year). It helps to reduce the number of queries to the server and accelerates content loading.
  • Enable Gzip compression to archive content prior to transferring it to users. It will speed up the process.

3. Leveraging Caching Solutions

What definitely makes Magento 2 server response time slow is overlooking caching, which is an irreplaceable helper for boosting TTFB. Apply at least these strategies in your online store:

  • Full-page caching (FPC). It’s used to cache all pages.
  • Block caching: for example, cache the header and footer.
  • Static content caching for images, fonts, JS, and CSS files.

Use the combination of several solutions to reach the needed result:

  • Redis and Varnish cache. Redis is a universal tool for any type of caching, while Varnish cache can replace Redis for FPC. In practice, these two solutions are sometimes used together, complementing each other and ensuring fast speed even if something goes wrong with one of the tools.
  • CDN (Content delivery network). This service caches static content and retrieves it from the server closest to the client. It significantly unloads the store’s server and accelerates all processes, including TTFB. As a result, people receive content quicker.

4. MySQL Optimization

  • Enable caching for queries returning the same results every time.
  • Configure indexes to make the database search work faster.
  • Rethink large database queries to make them execute quicker.

Check more tactics of in our recent guide.

Here is an example from the Magento store of one of Onilab’s clients. In the first screenshot from the Mirasvit profiler, you can see the “Total time” indicator: TTFB is about 4.5 seconds, including 123 milliseconds for database queries. It’s quite slow and needs optimization.

Mirasvit profiler TTFB indicator

The second screenshot reflects a far better website performance: 756.5 milliseconds in total and just 18 ms for database queries. What have we done? First, we rewrote database queries and got rid of heavy logic (optimized cumbersome calculations). Secondly, we turned on some caching. If we work with caching profoundly, TTFB will decrease even more.

Mirasvit Profiler improved TTFB

More Recommendations on Improving TTFB

To reduce server response time (TTFB) on Magento 2 further, we recommend considering the following improvements:

1. Make sure your server is capable of handling your ongoing traffic

TTFB can lengthen due to the shortage of server resources (e.g., RAM). Consider upgrading the server and\or using load balancing between two servers.

2. Is the used hosting enough to support your store?

Some providers save data on CPU, hard drives, and RAM. We advise you to opt for a faster SSD instead of an outdated HDD. Plus, look at the number of cores in the CPU (min 4, but the more, the better). And you can also buy more RAM (min 4 GB for a mid-size store and 16 or 32 GB for a large one).

3. Implement Lazy Loading for particular blocks

Basically, this practice is applied to , but you can leverage it for other cases. For instance, you have one of the blocks placed outside the above-the-fold area that takes much server time to load. Then you can defer loading it until a user starts scrolling.

4. Revise the extensions

There could be various unused or rarely used and ineffective modules. It’s better to disable them since they complicate the logic and therefore contribute to a longer server response time too.

5. Avoid excessive logging in production mode

Constant logging additionally slows down working with the file system, which is not fast itself. A good practice is to log only critical mistakes for further analysis.

6. Upgrade your Magento to the latest available version

As of June 2023, Magento 2.4.6 TTFB optimization is way easier than, e.g., Magento 1.9 TTFB optimization. Each subsequent version fixes some bugs of the previous one and requires newer module versions (PHP and others) that also perform faster than before. Switching to the latest software is a proven method to on the whole.

If you have some concerns over the Magento 2 migration process on the whole, its possible challenges, and pitfalls, read our article on .

7. Monitor the execution speed at the coding (code review) stage

Last but not least, examine the speed of modules right after installation and optimize them if needed.

These are primary tips on how to reduce server response time on Magento. For more details, read our guide on . We’ve also covered how to enhance other core performance indicators in the guide.

Summing up Magento TTFB Optimization

Magento TTFB optimization requires a lot of attention and diligent work. But don't let that demotivate you. First and foremost, these optimization practices favorably affect not only server responsiveness but also other performance indicators. And secondly, Onilab’s development team and our are at your disposal.

Related Articles

Website Speed Optimization: 9 Best Practices to Improve Performance
Alex HusarDmitry GaydukMary Sysoi
Three authors, Onilab LLC

Website Speed Optimization: 9 Best Practices to Improve Performance

10 min
Aug 28, 2023
Magento 2 Mobile Speed Optimization: A 2024-ready Guide
Alex Husar
Alex Husar, Onilab CTO

Magento 2 Mobile Speed Optimization: A 2024-ready Guide

14 min
Aug 22, 2023
Magento Optimization for Google PageSpeed Insights (Updated 2024)
Dmitry Gayduk
Dmitry Gayduk, Magento Team Lead

Magento Optimization for Google PageSpeed Insights (Updated 2024)

15 min
Jul 14, 2023
Magento 2 Speed Optimization: 32 Effective Fixes (Updated 2024)
Alex Husar
Alex Husar, Onilab CTO

Magento 2 Speed Optimization: 32 Effective Fixes (Updated 2024)

21 min
Jul 6, 2023

Magento TTFB Optimization FAQ

What is an acceptable server response time (TTFB)?

Google considers server response time under 800 milliseconds good. We'd recommend keeping TTFB under 200 ms for crucial Magento store web pages like home, categories, product, cart, and checkout. It not only positively affects the store's speed and UX but also contributes to a better PageSpeed Insights score.

Why Magento is too slow?

Each Magento store has peculiarities influencing its performance: Magento version, monolithic/headless architecture, customizations, used third-party modules, hosting solution, code quality, caching strategy, applied optimizations, etc. Therefore, your Magento 2/1 store must undergo meticulous profiling to identify the root causes of slow server response time.
But for almost any Magento store, server optimization and configuring block, full-page cache, and other Redis/Varnish caching solutions are the most powerful techniques to reduce the TTFB.

How to reduce server response time in Magento 2?

Slow server response time is quite a widespread issue for online stores, and Magento 2 is no exception. Optimizing Magento TTFB looks like a large chunk of work, but it also means improving other metrics (like CWV) and the overall user experience. So it definitely worth your while.
Reducing server response time for a Magento site, first and foremost, demands the involvement of the Magento backend developers. They will likely need to revise the Magento database, optimize web servers, set a load balancer, get rid of unused/outdated third-party extensions, enable Redis and Varnish cache, and so on.

Let’s stay in touch

Subscribe to our newsletter to receive the latest news and updates.