Posted at December 13, 2017 at 6:33 am
Magento 2 is a complex and highly configurable eCommerce platform. It supports endless level of customization. It lets you create a website with almost any functionality you can think of.
The price you pay for such a flexible eCommerce solution is performance. Magento 2 (M2) might be quite slow. I am sure you have seen people on the web searching for ways to speed it up.
I am going to share with you my 5 easy steps to fix a slow M2 site. You don’t need to have programming skills to implement them. Follow me.
Magento 2 functionality could be extended with custom 3rd-party plugins. You can develop your own extensions or buy them from various vendors. Most plugins are poorly coded. Unlike Magento core which was written by experts, custom extensions are coded by average programmers at most. With average skills and no appreciation for performance benchmarks. It is no wonder some 3rd-party extensions slow down a Magento 2 site. You need to do an audit to identify those plugins that affect site performance.
First get a list of all custom extensions. Go to Magento backend menu Stores > Configuration > Advanced > Advanced. You will see an output like this:
Those are all extensions that are installed on your Magento 2. Ones that start with Magento_ are core plugins and you should ignore them. Others are 3rd-party modules. Copy them to a special list ‘Custom Extensions’. Now go through ‘Custom Extensions’ list and disable modules one by one. How do you disable a module? You will need SSH (Secure Shell) for that. Use SSH to login to the server and navigate to Magento root folder:
cd /path/to/magento/root/folder
Then issue a command to disable a module:
php bin/magento module:disable Vendor_ModuleName
After you disable an extension benchmark site speed. You can use an online tool WebPageTest.org. Do you see a difference in page load time? If you do than that plugin is an abuser. Contact its vendor and ask for help. Or uninstall it or find an alternative. If there is no speed difference move to the next plugin. Sooner or later you will find a few extensions that are performance hogs.
Magento 2 requires powerful hosting to deliver decent performance. If your M2 is running consistently slow it might be just screaming out loud – I need more CPU and RAM!
Here is a simple trick I use to determine whether a poor hosting plan is the reason for poor M2 performance:
If you find out you need a better hosting plan – contact your hosting company and ask for one. If you were using a shared plan – go with VPS. If you were using VPS go with a dedicated server. Explore your options.
There are three Magento 2 modes: default, developer and production. Magento 2 is designed to be fast only in production mode. You might be surprised how many M2 sites are slow only because they are in developer mode. The reasons vary: a developer forgot to switch M2 to production, a data entry specialist turned on developer mode for testing purposes and never turned it off. You need to make sure you run M2 site in production mode only. You can find out what mode you are in now by running this simple SSH command inside Magento root folder:
php bin/magento deploy:mode:show
You can turn on production mode with this command:
php bin/magento deploy:mode:set production
This performance tip relates to known “feature” of Magento 2: if you enable JavaScript bundling your bundled JS file will be over 5Mb. Here is a bug report on GitHub https://github.com/magento/magento2/issues/4506.
5Mb file will kill M2 performance on slow mobile networks. You need to avoid that. Do not use JavaScript bundling option. It is not worth it. Go to Magento 2 backend menu Stores > Configuration > Advanced > Developer > Enable JavaScript Bundling and set JS bundling to No.
If you disable JavaScript bundling your frontend pages will request lots of individual JS files making lots of HTTP requests. That might be considered as a slow factor but only with HTTP/1. Here comes HTTP/2. This protocol was designed to make sites with lots of HTTP requests fast. It does that and many other performance optimization tweaks that make M2 deliver decent performance.
Contact your hosting and ask if they support HTTP/2. Let them enable HTTP/2 for your Magento 2 store.
Magento 2 comes equipped with Full Page Cache. It means M2 can cache whole pages making time to first byte (TTFB) for cached pages around 500ms i.e. half a second. This is good news. You need to make sure Full Page Cache is always on. Go to backend menu System > Cache Management and double check. You might be surprised to see all your cache disabled. Your developer might have turned it off for testing purposes and forgot to put it back on. No wonder you are experiencing performance problems!
Magento 2 supports Varnish out of the box. Varnish is a special software that caches and serves static content. It helps with making TTFB as low as possible. Contact your hosting support team to have Varnished installed and configured on your server.
You can enable Varnish for Magento 2 Full Page Cache at backend menu Stores > Configuration > Advanced > System:
Those were my 5 tips to speed up Magento 2. They are field-proven and tested. I used them many times to optimize performance of slow M2 sites. I hope you find them useful.
About the author: Konstantin Gerasimov is a Magento Certified Developer with Goivvy.com. He specializes in backend development, speed optimization and extension creation.