• Explore. Learn. Thrive. Fastlane Media Network

  • ecommerceFastlane
  • PODFastlane
  • SEOfastlane
  • AdvisorFastlane
  • TheFastlaneInsider

3 Ways To Improve Magento 2 Server Response Time

Orange background with text: "3 Ways to Improve Magento 2 Server Response Time for Enhanced Ecommerce Performance.

Magento 2 eCommerce platform could be slow.

There are different ways to speed it up and improving time to first byte (TTFB) is one of them.

In this article I’ll show 3 ways to lower server response time. You’ll need minimal programming skills to implement them.

1. PHP Code Profiler

Code profiler shows what’s going on inside Magento when it processes page requests.

It shows function calls and times it took to execute them. You can find the slowest parts and investigate.

Magento 2 comes with a built-in profiler but its functionality is limited. I’d recommend using an online profiler (Tideways, New Relic or similar, just google them, they are all good.)

Analyze different page types (catalog, product, homepage, checkout) and see if you can find code parts that are slow.

2. 3rd-party Extension Audit

From my experience a poorly coded custom module is the number one reason why Magento 2 server response time is long.

I’d suggest doing a 3rd-party extension audit: turn all plugins off and see if it makes any speed difference. If a site becomes faster, turn them on one by one and find a module that breaks performance.

After you find an ‘abuser’ – try to contact the vendor and let them know of the problem. They could suggest a patch.

You can also find an alternative on Adobe Commerce Marketplace or simply delete the plugin if you don’t need it.

3. Full Page Cache Lock

I know that Cache != Performance.

But…

You can greatly improve time to the first byte if you stop automatic full page cache flushing and keep it intact for a week or a month.

It would work if your eCommerce store doesn’t have too many product updates and content stays pretty much the same.

I’ll show you how to place a full page cache lock. Suppose you run Magento 2.4.6 and have the configuration Stores > Configuration > Advanced > System > Full Page Cache > Caching Application set to Built-in Cache:

Open up a file vendor/colinmollenhour/cache-backend-file/File.php and make the following changes:

public function remove($id)

  {

return; // add this line at the function start

…..

 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())

  {

        return; // add this line at the function start

……

protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())

     {

         return; // add this line at the function start

……

protected function _cleanNew($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())

     {

       return; // add this line at the function start

public function ___expire($id)

     {

       return; // add this line at the function start

Now Magento will keep the full page cache forever, you just have to flush it manually every week or every month. Otherwise it will take up all storage space.

You can go one step further and warm the cache right after you flush it. Compose a list of your most popular pages and fetch it one by one to make sure they are cached before a customer requests them. You can write a simple bash script to do it for you.

Takeaway

There are certain ways to make Magento 2 store faster and improve its server response time:

  • Use a PHP code profiler to find slow code blocks
  • Do a 3rd-party module audit to find slow extensions
  • Prevent Full Page Cache flushing and have lower time to the first byte across the whole website

You don’t need advanced programming skills to implement the fixes I suggested.

If you have any questions – please don’t hesitate to leave a comment or contact me directly.

Essential Industry Insights for Further Reading

You May Also Like
Share to...