Magento 2 is the next generation of the popular eCommerce platform. Among the main features of it is improved performance as compared to M1.

Indeed M2 comes with Full Page Cache in a free Community Edition.  M1 has it in Enterprise version only.

But still we see lots of slow Magento 2 complains. How to fix it? Below I will give you 7 ways to boost M2 performance.

7 ways to speed up Magento 2 performance

 
  1. Audit 3rd party extensions

  2. Profile TTFB (time to first byte) with a profiler

  3. Hosting

  4. Make sure you are in production mode

  5. PHP7

  6. Full Page Cache is on (built-in)

  7. CSS/JS bundle/merge/minify

Audit 3rd party extensions

Based on my experience with Magento I would say: the more custom plugins you have installed the slower your site is.

That is true. Mostly because those plugins are poorly written. Your job is to identify those that affect performance and remove or substitute them.

How do you do that? Easy: deactivate plugins one by one and benchmark site speed. Once you get the abuser contact the vendor you bought the extension from and ask if they could provide a patch. Or shop for an alternative.

Profile TTFB with a profiler

TTFB  or time to first byte is how long a browser should wait before receiving the first byte from the site server. TTFB includes download time, network latency and server response time.

Server response time is the time Magento takes to renders HTML to be sent to a browser. We will need to profiler that time and understand what code functions and calls it is spent on.

First fire up a profiler. Magento 2 comes with a default one you can use. Simply set MAGE_PROFILER server variable to 1 and it should be activated.

I also find free Mirasvit profile toolbar quite useful. It visualizes the trace for better understanding.

You can also use PHP profiler xhprof or some paid solutions.

Once you have your page trace look for calls with most time spent. Then analyze corresponding files .php or .phtml. See if you can spot unoptimized patterns like loading a Magento model in a loop:

<?php foreach($category->getProductCollection() as $product): ?>
<?php $mode = $productModel->load($product->getId(); ?>
<?php endforeach; ?>

You might be surprised but I see this pattern way too often on client’s sites. 

Sign up for better hosting. Just try and benchmark.

Try better hosting. Seriously. Sign up for a bigger and more expensive plan and see if it makes any difference. If difference is huge then your current server is just not enough for Magento 2. If you can hardly tell the difference then you are good where you are.



Production Mode

Magento 2 has three running modes: default, developer and production. Production mode is the fastest among those three. For various reasons: code compilation, static resources materialization and some internal code improvements.

You want to make sure you run in production. To do that run:

php bin/magento deploy:mode:show

It will tell you the current mode. To change mode use:

php bin/magento deploy:mode:set production

PHP7 for better performance

PHP7 is almost 25% faster than PHP5. Magento 2 supports PHP7 out of the box. Ask your hosting if they use the latest php. If you host your own server - upgrade immediately!

Full Page Cache (FPC) is on

This is trivial but it might be off for various reasons. Your developer could forget to enable it after those frontend updates he/she ran recently. You never know.

Go to System > Cache Management and make sure FPC is green. It won’t kill to double check.

CSS/JS bundle/merge/minify

Magento 2 can minify, merge and bundle CSS and JavaScript. All out of the box without any extensions.

Should I say those features are good for speed? Enable them at Stores > Configuration > Advanced > Developer. Keep in mind they are only effective in production mode.

Site speed is very important. It is even a search ranking factor.  I hope these 7 tips I shared will help you fix slow Magento 2 site.