A Complete Guide to Magento 2 Speed Optimization

A Complete Guide to Magento 2 Speed Optimization

No one likes slow checkouts. E-commerce websites should be fast. Speed is important not only from customer’s perspective but for search engines as well. The fact that speed is now a major ranking factor in Google’s search algorithm has increased its importance many fold.

Magento, being a widely used e-commerce platform, is relatively more complex and if not setup correctly, tends to be sluggish. You need to take immediate steps to speed up your Magento 2 website as otherwise; it will take away a considerable number of prospective customers. This infographic explains how badly a delay of even 1 second affects your site’s bounce rate and conversions.

How to Speed up Magento 2?

Various factors contribute to your Magento 2 store being slow. There are, nonetheless, different ways to counter each factor. In this article, we are going to propose all the possible Magento 2 performance optimization tips. Some of these tips will have striking results while others will be less noticeable. In no particular order, let’s discuss them one by one. At this stage, you might want to check your Magento 2 page speed to see how much it has improved after you have applied these tips.

The 10 Proven Magento 2 Speed Optimization Tips

  • Choose the Right Hosting
  • Enable System and Full Page Caches
  • Inspect 3rd Party Extensions
  • Use Optimized Images
  • Switch to PHP 7
  • Turn Production Mode ON
  • Minify and Merge JavaScript/CSS
  • Enable Flat Categories & Products
  • Setup Content Delivery Network
  • Update to the Latest Stable Magento 2 Version

1. Choose the Right Hosting

A hosting plan is a foundation of a fast website. Always go for a premium hosting plan. This investment will pay off in the form of quick server response. Magento stores can be really big and cheap hosting plans just don’t help.

How do you know you need to change or upgrade your hosting plan? Here is a simple tip to help you decide. Install a fresh copy of M2 on the same server your live site is running on. Keep in mind this should be the same version as your live store. Benchmark your fresh copy against your live M2 site. If this fresh copy is significantly faster than your live store, you don’t need to change anything. If it is slow then your hosting resources are simply not enough to power Magento 2. Get a different plan or sign up for those Magento 2 optimized servers you could find on the web.

Also, choose a server location that is in your target market or as close as possible.

Recommendation: How to Choose the Right Hosting For Magento 2?

2. Enable System and Full Page Caches

Cache management is the key to Magento 2 speed optimization and has a significant impact on performance. The good news is that it can be easily done from the backend.

Go to System -> Cache Management. All of the cache types should be set to ENABLED. If they are not, choose “Select All” from the dropdown, Enable, and press the Submit button.



3. Inspect Third Party Extensions

Third party extensions are one of the most common reasons for a slow Magento 2 site. Either your site has too many extensions installed or they are poorly coded. Your site will not only have to load the site content but all the extensions also which will significantly affect the loading time.

Your task is to find all the abusive/unused plugins and eliminate them. Make an audit of every extension by disabling them one by one. If by disabling an extension you notice a significant difference in speed, you have found the abuser. Now you can contact the vendor and ask for help, find an alternative, or simply uninstall the extension.

You can disable an extension by accessing the server using SSH credentials and running the following command.

 
php bin/magento module:disable VendorName_PluginName

and to enable it again, replace “disable” with “enable”.

Alternatively, you can uninstall an extension by deleting it from the app/code folder. Run this command after you do this.

 
php bin/magento setup:upgrade

4. Use Optimized Images

Your M2 site can be slow due to heavy images. Images are heavy content which can seriously slow down your site. To reduce page load time and enhance UX, make sure you use compressed images without compromising the quality. It is recommended to use product images in JPEG and logo in PNG format.

5. Switch to PHP 7

Although Magento 2 supports PHP 5.6 but performance can be improved a great deal by switching to the latest PHP version which is PHP 7.

You can switch to the latest Php version from the cPanel or manually by adding directives in the .htaccess file of your store: For example, to switch to PHP 7.3, add the following directive.

AddHandler application/x-httpd-php73 .php .php5 .php4 .php3

Note that it will change the PHP version in the subfolders also. Also, make sure the above PHP version is installed on your server before making these changes.

6. Turn Production Mode ON

Many people just completely skip this step although it is very important and simple. Magento 2 has 3 running modes, default, developer, and production. Production mode is the fastest of them all so if you want maximum performance and fast speed, you need to switch to production mode. Default and developer modes are for debugging purposes.

Log into your server using SSH and navigate to the root directory of Magento. To find out which mode are you running in, apply this command.

 
bin/magento deploy:mode:show

To switch to production mode, type

 
bin/magento deploy:mode:set production

Complete Tutorial: Set Magento 2 Modes - Developer, Default, & Production

7. Minify and Merge JavaScript/CSS

Minification is one of the methods to reduce load time by minimizing the code. Merging JS and CSS files will result in fewer server requests. This feature was absent in Magento 1. To speed up Magento 2, configure these settings in the backend.

  • Go to Stores -> Configurations -> Advanced -> Developer
  • Under JavaScript Settings, Set the Minify JavaScript Files field to ‘Yes’.
  • Now expand CSS Settings and set the Merge CSS Files and Minify CSS Files fields to ‘Yes’. Click the Save Config button and clear the cache.


8. Enable Flat Categories and Products

Reading data from different tables of the database may cause delays. A good idea will be to get frequently read data from different tables and merge it into one easily accessible table. This will reduce the database read time and data will be loaded much faster.

  • Go to Stores -> Configurations -> Catalog -> Catalog and expand Storefront.
  • Set both the “Use Flat Catalog Category” and “Use Flat Catalog Product” to “Yes”.


9. Setup a Content Delivery Network (CDN)

The further you are away from your server, the longer it takes and ultimately the slower the website. If you have customers all around the world which most e-Commerce websites have, setting up a CDN will significantly reduce the amount of distance between the user and the server. It accomplishes this by setting up CDN endpoints in as many locations around the world as possible. So when a user tries to access the content, it is first retrieved by the content delivery network service and then distributed around the world. Every user now instead of sending request to the server thousands of miles away, can access it directly from their closest CDN. The result is improved speed.

How to Setup CDN in Magento 2?

  • Log in to your Admin Panel and navigate to Stores -> Configuration -> General -> Web.
  • Expand the Base URLs section.
  • Enter the CDN ULRs for the Static View Files and User Media Files (JavaScript) in Base URL for Static View Files & Base URL for User Media Files respectively.
  • Now expand the Base URLs (Secure) section.
  • Enter the same data in Secure Base URL for Static View Files and Secure Base URL for User Media Files fields.

Save the changes.



10. Update to the Latest Stable Magento 2 Version

Lastly, if your Magento 2 version is not the latest, update it. This is important because the latest stable version will have the newest features and upgraded performance which your store should not miss. You can check your current Magento 2 version by logging into the backend and scrolling down to the bottom of the page. This guide will help you if you want to upgrade to the latest Magento 2 version.

Conclusion

There are many variables involved when it comes to Magento 2 speed optimization. In this article, we have covered some very basic and relatively advanced methods using which you can drastically improve the performance of your Magento 2 store. If you think your Magento 2 is still slow and needs further fine tuning, you can hire our professional Magento 2 speed optimization experts.