Nexcess Logo

How to optimize Magento performance

Knowledge Base Home

Notice anything different?

We've enhanced the appearance of our portal and we're working on updating screenshots. Things might look different, but the functionality remains the same.
February 17, 2023

One of the actions any Magento store owner should perform when traffic declines, bounce rates increase, and conversion rates remain flat is Magento performance optimization. Slow Magento stores frustrate customers and reduce conversion rates. Additionally, a slow website hurts your SEO rankings.

People chose Magento as one of the top CMSs available because of its remarkable features, distinct functionality, and speed.

How to optimize Magento performance

You'll discover all of the critical Magento performance optimization fixes and recommendations in this article to help your Magento store run more quickly. As a result, your server response time, Google PageSpeed, and Core Web Vitals ratings, among other things, will improve.

An overview of Magento performance improvements

Magento is speedy in terms of site performance when using a limited set of test data. However, it starts to decline as soon as you bring on new features, customizations, and third-party modules.

When you evaluate Magento website speed, you can determine what factors contribute to a website's poor performance because the majority of website speed testing tools give you clear performance reports. You can discover how to optimize Magento performance using such a report.

Techniques for optimizing Magento performance for Magneto 1 or Magento 2

There are various techniques that can be used to optimize Magento performance. To determine the ideal approach, consider your needs and the level of technology required by each method.

1. Select reliable Magento hosting

If you've decided to use Magento to develop your website, your next decision is to choose a reliable Magento web hosting. Why not trust Nexcess the way many of the most experienced Magento users have? It has been shown that there are a lot of attractive elements, and they build up quickly:

  • Instant autoscaling, dedicated IP addresses, and server-side scripting.
  • Performance testing on demand to diagnose issues and optimize Magento site speed.
  • Our integrated edge CDN provides more than 280 locations worldwide and cutting-edge caching for lightning-fast loading.
  • 24/7/365 monitoring of the security situation and assistance from Magento professionals.
  • PHP workers and resource base for reliable performance.

If you are starting with Nexcess, you are in the right place. Nexcess will help you begin hosting Magento sites by giving you a selection of educational resources and practical videos. The service that Nexcess provides is known as Managed Magento hosting. The hosting for Magento is optimized. The website will become faster, safer, and more scalable as a result of our technology and infrastructure that was developed specifically for the Magento platform. Intelligent monitoring tools built in to assist you in keeping it that way. This is why the use of Nexcess hosting by Magento users is a wise business decision.

2. Update the Magento application software to the most recent release

The security and optimization of the platform are the main areas of focus for the frequent version updates that Magento delivers. As a result, updating your Magento store to the most recent version is the most fundamental and crucial advice for increasing Magento 2 speed optimization. All those seeking quick solutions for how to optimize Magento performance, should perform the necessary platform upgrades do that your version of Magento 2 is current.

If you are currently using Magento 1, we highly advise that you upgrade to Magento 2 to benefit from a better, more dependable, secure, and quicker ecommerce system. To improve performance with optimization, switch to Magento 2.

3. Utilize Varnish for full page caching

Use Varnish instead of files to accomplish full page caching. Varnish or Redis are both recommended by Magento for use in production. However, when Redis is compared to Varnish, Varnish wins in terms of speed.

The advanced Varnish technology is meant to speed up HTTP traffic with an integrated full page caching using in-memory technology, which is faster than that of a file system or database. Those assets are significantly slower.

To configure Magento 2 to use Varnish, follow the below steps:

  1. From the Magento 2 Admin Panel, navigate to Stores > Configuration > Advanced > System > Full Page Cache.
  2. From the Caching Application list, choose Varnish Cache (Recommended)
  3. Add a value in the TTL for Public Content field.
  4. Expand Varnish Configuration and add specific information about your Varnish configuration.

You can visit our page on How to enable Varnish for Magento 2 on Nexcess Cloud to learn more about the Varnish setup instructions.

4. Speed up Magento 2 via Redis

Redis is a distributed memory cache that accelerates large-scale online applications with dynamic databases in Magento 2. By delivering cached data when an external data request permits it, the stress that database requests place on servers is minimized.

Furthermore, by choosing Redis, you have in place a high-speed backend cache with complete cache tag support that can be included without requiring an additional low-level file system cache.

The performance is, therefore, outstanding and stable, especially for Magento stores with significant traffic. To learn more about the Redis setup instructions, you can visit our page on How to configure Redis for Magento 2.

5. Turn on Magento cache management

The caching system used by Magento 2 to increase speed operates similarly. Magento will make a copy of your website and store it in the client's local cache. Instead of building a new website for every request from the browser, Magento returns the original copy when the user returns later.

Magento's built-in caching types include page cache, integration configuration, client alerts, and web service configuration. Fewer database operations are needed for page requests when caching is enabled. You must be sure to keep them all turned on.

You can use the CLI command below to enable Magento's full page cache:

php bin/magento cache:enable full_page

You can use the CLI command to enable cache types:

php bin/magento cache:enable

To turn on Magento cache management, you can follow the below steps:

  1. Go to System > Cache Management in your Magento Admin Panel.
  2. Select every field, then click the Submit button.
  3. Check if all cache types have the label Enabled and the status set to green.

To turn on Magento cache management, you can use this screen.


6. Use Elasticsearch for search and catalog pages

Elasticsearch offers incredibly fast full-text searches. In addition, since the indexing service runs on the server instead of searching the full database for the match, it provides quick web content search functionality.

Elasticsearch is helpful for maintaining the accuracy and speed of your Magento store search. By doing this, you can improve the user experience and ensure that visitors to your Magento store will enjoy their stay there.

To configure Magento to use Elasticsearch, you can follow the below steps:

  1. From the Magento 2 Admin Panel, navigate to Stores > Settings > Configuration > Catalog > Catalog > Catalog Search
  2. From the Search Engine dropdown list, choose the Elasticsearch version and enter Elasticsearch Server Hostname and Elasticsearch Server Port in the corresponding fields.
  3. Click on the Test Connection.

To configure Magento to use Elasticsearch, you can use this screen.


To learn more about the Elasticsearch setup instructions, you can visit our page on How to configure Magento 2 to use Elasticsearch.

7. Implement a Content Delivery Network (CDN) to optimize the speed of loading Magento 2 webpages

Caching static material from Magento stores, such as CSS, JavaScript, photos, videos, typefaces, etc., is done using a Content Delivery Network (CDN). As a result, the store's response time for users gradually decreases. The CDN takes over the request process and begins providing the static web content to reduce the time for loading a page in the user's browser due to the node's widely dispersed locations.

All Managed Magento hosting plans include the Nexcess CDN. For a better customer shopping experience, configure CDN for your Magento stores. To find out how Nexcess customers may utilize their client portal to set up the Nexcess CDN solution for usage with their Magento 2 store, you can visit our page on How to set up CDN access for Magento 2. When you are studying how to optimize Magento performance, CDN integration is vital.

8. Enable the production mode in Magento

Magento has three operating modes: default, development, and production. A production system should use the production mode when it is deployed. This mode prevents you from enabling or disabling different cache types in Magento Admin, hides exceptions, and only serves static content from the cache. It also disables automated code file compilation.

The developer mode is active while working on the store. So, when deploying your site to the live server, don't forget to switch to production mode.

To view the current mode, you can use the following command:

php bin/magento deploy:mode:show

To switch to developer mode, you can use the following command:

php bin/magento deploy:mode:set developer

To switch to production mode, you can use the following command:

php bin/magento deploy:mode:set production

9. Keep the Indexers up to date

To speed up load times, Magento enables you to interact with large amounts of data. To address this, Magento must reindex its indexers because the core system updates indexers on every object stored by default. You must manually update the indexers because the process is not perfect.

The Magento 1 Admin Interface allows for the updating of indexers. However, to run reindex via the command line, you will need to run the following CLI command on the root directory for Magento 2:

php bin/magento indexer:reindex

To learn more about reindexing in Magento, you can visit our page on How to issue a reindex in Magento.

10. Activate "Update on Schedule" for indexers

There are two options for the Magento indexers: the "Update on Save" or "Update on Schedule" option. Every time you save a product, attribute, or category when they are configured to "Update on Save," the particular index begins to run. Indexers can become resource-intensive, which could cause your server to run more slowly.

The "Update on Schedule" option is the ideal setting for the indexers. By doing this, you can be certain that the cron job will carry them out at the time you choose. Choose a time when your website's traffic is low. When you are looking for ways how to optimize Magento performance, employing the scheduling feature described here is key.

To view the current indexers mode, you can use the following command:

php bin/magento indexer:show-mode

Navigate to System > Index Management from the Magento 2 Admin Panel to view the current indexers mode.

To change the indexers mode to “Update on Schedule,” you can use the following command:

php bin/magento indexer:set-mode schedule

From the Magento Admin Panel, go to System > Index Management. Select all indexers, and then from the Actions dropdown select “Update on Schedule":

From the Magento Admin Panel, go to System > Index Management. Select all indexers, and then from the Actions dropdown select “Update on Schedule."


To change the indexers mode to “Update on Save,” you can use the following command:

php bin/magento indexer:set-mode realtime

To configure the Scheduled Tasks from the Magento Admin Panel, go to Store > Settings > Configuration > Advanced > System > Cron (Scheduled Tasks). Then, expand “Cron configuration options for group: Index” as shown:

To configure the Scheduled Tasks from the Magento Admin Panel, go to Store > Settings > Configuration > Advanced > System > Cron (Scheduled Tasks). Then, expand “Cron configuration options for group: Index” as shown.


11. Leverage Magento 2 image optimization

As a result of faster download times, optimizing your product photos can significantly speed up your websites. Discovering how to optimize Magento performance, means learning how to optimize your website's media assets.

There are a lot of plugins you can use to optimize images automatically, or you can compress them before uploading them using a program like Photoshop. Speed improvements to Magento 2 websites are most noticeable with optimized images. Furthermore, it is one of the ways for lowering page weight.

You can optimize images for Magento 2 using a variety of techniques. Some of them are as follows.

  • Images compression: You can significantly reduce a page's size by compressing images before uploading them to your website.
  • Images preloading: This method is frequently applied to product sites, especially when each page contains multiple images. When a new website page is opened, image preloading enables users to select one image to load first while additional images are uploaded later.
  • Lazy loading: Using this method, images can load as website visitors scroll down the page. In this manner, the website only loads the images that the user can see. The user mustc scroll down to see the remaining images, which remain idle until they are loaded. On mobile devices, lazy loading is very helpful for increasing speed.
  • Image CSS Sprites: A page with several images takes a long time to load and creates multiple server requests. A group of images that have been grouped together to create a single image is called an image sprite. You can speed up your website by using this strategy to lower the number of server queries and conserve bandwidth.
  • Enable Fastly Image Optimization (Fastly IO): This Magento 2 feature allows for considerably faster picture production using image compression. Fastly IO is an excellent tool for working with many formats such as jpeg, png, and gif. In addition, Fastly has certain unique features, including promoting loss conversion, using adaptive pixel scaling for various screen resolutions, and resizing product images from lossy to lossless and vice versa.

13. Use Gzip file compression and Apache's mod_deflate module

Gzip is a technique for file compression that speeds up network transfers. By using file compression, your web server can offer customers reduced file sizes that load more quickly.

You may add this enhancement for network file transfers by changing your .htaccess file and uncommenting the relevant lines as shown below to enable Gzip file compression and switch on Apache's mod_deflate module. To deliver static resources more quickly to the browser, the mod_deflate module first compresses them into smaller files.

<IfModule mod_deflate.c>

############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

    # Insert filter on all content
SetOutputFilter DEFLATE


    # Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json image/svg+xml


    # Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html


    # Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip


    # MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html


    # Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary


    # Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

</IfModule>

14. Disable flat catalogs

Due to fewer SQL queries and data consolidation, Magento flat catalogs were employed to speed up the Magento website. Both Magento 1.x.x and 2.x.x ran smoothly. But it ended up being the root of the significant dependencies that appeared, which affected performance and caused other indexing problems. Since Magento 2.1, using flat catalogs is not a recommended practice. Therefore, turning them off is one method for improving Magento's speed.

To disable flat catalogs, you can follow the below steps:

  1. From the Magento 2 Admin Panel, navigate to Stores > Configuration > Catalog > Catalog > Storefront.
  2. Set Flat Catalog Category and Use Flat Catalog Product value to No.
  3. Click on Save Config to save the changes.

To disable flat catalogs, you can use this screen.


15. Merge and minimize the JavaScript (JS) and Cascading Style Sheets (CSS) files

You can combine CSS and JavaScript files into one file rather than keeping them separate to reduce page load times and optimize your website effectively.

JavaScript (JS) files

To merge and minimize the JavaScript (JS) files you can follow the below steps:

  1. From the Magento 2 Admin Panel, navigate to Stores > Configuration > Advanced.
  2. Under Advanced, click on Developer.
  3. Set Minify Javascript Files and Merge JavaScript Files value to Yes in the JavaScript Settings section.

To merge and minimize the JavaScript (JS) files you can use this screen.


Cascading Style Sheets (CSS) files

To merge and minimize the Cascading Style Sheets (CSS), you can follow the below steps:

  1. Set Merge CSS Files and Minify CSS Files value to Yes in the CSS Settings section.
  2. Click on Save Config to save the changes.

To merge and minimize the Cascading Style Sheets (CSS), you can use this screen.


16. Use Cascading Style Sheets (CSS) critical path

You can choose which CSS files should load first and which ones can wait by utilizing critical CSS. In this method, render-blocking resources are removed, and the First Meaningful Paint (FMP) is greatly improved while non-critical styles are reloaded asynchronously.

To configure the path to the critical CSS file, you can follow the below steps:

  1. From the Magento 2 Admin Panel, navigate to Stores > Settings > Configuration > ADVANCED > Developer.
  2. Set CSS Critical Path value to Yes.
  3. Click on Save Config to save the changes.

To configure the path to the critical CSS file, you can use this screen.


You can view the Developer tab only in development mode. To enable CSS critical path in production mode, you can run the following command from the Magento root directory:

bin/magento config:set dev/css/use_css_critical_path 1

17. Disable JavaScript (JS) bundling

The goal of JS bundling is to consolidate JS files into large bundles and minimize the number of HTTP connections sent to the server to load the page. However, it actually makes the Magento site slower rather than faster.

Even if the page needs files from one or more JS bundles, the webpage won't load until the browser downloads all of the JS bundles. Additionally, Magento loads JS bundles each time a browser requests a new page. This is not the ideal strategy to optimize Magento performance, given that JS bundles often range in size from 5 to 10 MBs.

To disable JS bundling, you can follow the below steps:

  1. From the Magento 2 Admin Panel, navigate to Stores > Configuration > Advanced > Developer > JS Settings.
  2. Set the JavaScript Bundling value to No in the JavaScript Settings section.
  3. Click on Save Config to save the changes.

To disable JS bundling, you can use this screen.


18. Use Magento log cleaning

The database backup and your entire Magento store will run slowly because of the Magento log. Cleaning these logs on a regular basis will help you optimize your Magento website and increase speed and performance.

By following the below steps, you can clean up Magento database logs without having to access Magento databases:

  1. From the Magento 2 Admin Panel, navigate to Stores > Configuration > Advanced > System.
  2. Under System, see MySQL Message Queue Cleanup.
  3. Set the values for Successful Messages Lifetime, Retry Messages In Progress After, Failed Messages Lifetime, and New Messages Lifetime as default or automatic clearance per your requirements.
  4. Click on Save Config to save the changes.

By using this screen, you can clean up Magento database logs without having to access Magento databases.

19. Expire headers

If a file is to be downloaded from the server or stored in the browser's cache, the browser is instructed by expire headers:

<ifModule mod_expires.c>
    ExpiresActive On
    ############################################
    ## Add default Expires header
    ## https://developer.yahoo.com/performance/rules.html#expires
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
</ifModule>

20. Disable ETags

ETages give browsers the ability to check cached page elements from one visit to the next. They are helpful, but sometimes they might affect websites that are hosted on server clusters. The performance will frequently be enhanced by disabling them as follows:

############################################
## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags
    FileETag none

About the importance of Magento 2 performance optimization

By reading the content above you learned how to optimize Magento performance — and it matters for you online store operations. Magento 2 performance optimization is essential in leading your business to success for Magento 2 stores. The success of your Magento shop and possibly even your entire business depends on your website's loading speed, which directly impacts your conversion rate.

A trusted provider for online businesses

See why 500,000+ trust Nexcess to keep their sites fast, secure, scalable, and fully supported.

Nexcess provides powerful Managed Magento hosting that accelerates your store's potential without ongoing maintenance, so you can easily set up your Magento 2 store from your side. Feel free to contact our Magento performance optimization experts if you have any questions or need assistance.

Recent articles

Related articles

Note about the original publication date


This article was originally published in September 2019. It has since been updated for accuracy and comprehensiveness.

Mohammed Noufal
Mohammed Noufal


Mohammed Noufal is a B.Tech graduate with a decade of experience in server administration and web hosting. He has a specialization in various cloud technologies and server management, including monitoring, configuring, troubleshooting, and maintenance.

He is a father to two daughters and finds fulfillment in their growth. In his free time, he enjoys blogging about technology, sharing experiences, traveling, making new friends, social networking, and listening to music.

With a strong technical background, family commitment, and creative outlets, he represents a well-rounded life journey.

We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.