Magento 2 (M2) is the next generation of a well-known e-Commerce platform. It’s a highly customisable solution to power online stores. The price you pay for that level of flexibility is always performance. Magento 2 can be slow. Forums and community boards tend to have people complaining about the poor page load times, so our top tips to speed up Magento 2 will help.
We all know that site speed matters to SEO. So, in order to have better search rankings we have to make sure our Magento 2 store runs as fast as possible. Of course, you can hire expert programmers to speed up your site. But, what if you don’t have the budget for it?
Don’t worry! In this article, 5 field-proven ways will be revealed so you can increase your Magento 2 performance, with no programming skills required!
5 Tips To Speed Up Magento 2
- Remove Slow Third Party Extensions
- Switch On Production Mode
- Get More CPU and RAM
- Disable JS Bundling
- Set Varnish as Full Page Caching Application
1. Remove Third Party Extensions
Based on experience, most custom extensions make Magento 2 slow. A fresh copy of M2 runs pretty fast with approximately a half-second page load time. But, things start to look bad when you add third party extensions.
A drop in performance is no surprise when third party extensions are thrown into the mix: Magento 2 is written by experts, whilst custom extensions are coded by amateur programmers at most. With average skills and no appreciation for performance, Magento 2 will slow down massively.
You need to identify and eliminate extensions that slow your store down. Firstly, get a list of all custom extensions. Go to Magento’s backend menu – go to: Stores > Configuration > Advanced > Advanced.
These are all the installed extensions. You have to ignore those that start with Magento_ as those are the core extensions – write down the remaining ones.
Now that you have the list of third party modules, you then need to disable them one-by-one and benchmark the page speed. To disable an extension, you need to SSH (Connect via Secure Shell) to the server. You can obtain SSH credentials from your hosting support team. Once you have done this, go to Magento root folder and run this command:
php bin/magento module:disable Extension_Name
It will disable Extension_Name and you can benchmark the page load time. If the speed stays the same, proceed to the next plugin.
To switch an extension back on run:
php bin/magento module:enable Extension_Name
Once you have identified the slow modules, contact its vendor and let them know the problem. You might want to find an alternative or remove them completely.
2. Switch On Production Mode
Magento 2 has three running modes: default, developer and production. The latter is the fastest one. If your store is slow, chances are your developer left it in developer mode. You need to make sure you are always in production.
To find out what mode you are in now, SSH to the Magento root folder and run:
php bin/magento deploy:mode:show
To switch to production mode run:
php bin/magento deploy:mode:set production
This command might take approximately 2-5 mins. It compiles code and deploys static content. You will see a screen like this:
Whilst the command is running, your store will be inaccessible as it will be in a maintenance mode.
3. Get More CPU and RAM
Magento 2 needs a powerful hosting to run fast – you can’t expect decent performance from a cheap shared monthly plan.
There is a simple trick to find out whether hosting resources are enough for M2. To do this:
- Install a fresh copy of Magento 2 (the same version) on the same hosting that your live site is running on.
- Benchmark the fresh M2 speed against the live site.
- Is the fresh copy significantly faster? Then your hosting is OK and the performance problem lies within the live site’s codebase.
- Is the fresh copy as slow as your live site? Then you need to either upgrade or change a hosting plan.
If this test shows you need a new hosting plan check out servers that are optimised for Magento. They are more expensive, but you get the performance boost you wouldn’t have gotten otherwise.
4. Disable JS Bundling
5. Set Varnish as a Full Page Caching Application
Varnish is a special software to serve and cache content. It makes sites insanely fast. Magento 2 supports Varnish natively – so, you should take advantage of it. Here is a diagram of M2 + Varnish setup.
The tricky part here is to get Varnish installed on the server. Your hosting support team should help you with that. In most cases it will be just a package installation, so it won’t be too complicated for the hosting support team to install it.
Next, you need to set Varnish as a Full Page Caching Application. Go to backend menu Stores > Configuration > Advanced > System and set Caching Application to Varnish Cache.
Once it’s done, Varnish should accept incoming requests and either query Magento 2 or serve cached content. Page load time with Varnish can be as low as 100-200 ms.
About the author: Konstantin Gerasimov is a Magento Certified Developer with Goivvy.com. He specialises in Magento backend development, performance optimisation and extensions development.