magento 2 performance optimizatoin

6 Essential Steps for Magento 2 Performance Optimization for Your Store (2024)

Optimizing the performance of the Magento 2 website is critical for its success. The rate at which a website converts its visitors into customers can be impacted by the speed at which it loads. Therefore, it is essential to have a highly optimized Magento installation to ensure the success of your Magento store and, potentially, your entire business.

In this blog, We will explain how Magento 2 developers can optimize Magento installation. Here are steps that must be followed and verified in your speeding up for Magento 2, which is a straightforward process.

6 Essential Steps for Magento 2 Performance Optimization

Magento 2 is a stable and user-friendly eCommerce platform. Nonetheless, various issues, such as improper extensions, misconfiguration, obsolete versions, and so on, might contribute to the Magento 2 store's poor loading performance.

By following these six essential steps, you can drastically optimize the performance of your Magento 2 store, giving your consumers a faster and more delightful experience.

1. Verify your Magento server hardware

Magento needs some basic hardware to perform the operations based on the number of concurrent customers at the Magento website.

RAM Memory:

A small Magento site needs at least 2GB RAM to operate. Sometimes, it breaks during the upgrade, installation and elastic search indexing. To solve this temporarily, you must create the swap file to run the operation.

CPU Cores:

A small Magento site hosting Magento 2 on Virtual Server needs a minimum 2vCPU or higher. For Dedicated Servers, choosing a plan with at least Quad Core 2.4GHz or higher is recommended.


A small Magento site needs a minimum of 20GB SSD to 100 GB Disk to operate based on images and content of the website.

2. Verify your cache Magento 2 installation

Magento provides various types of caching systems to speed up the site.

Magento Full Page Cache

When users visit your online store, the server processes their request using PHP and database queries to return an HTML response. A full-page cache stores the HTML response to speed up future identical requests, resulting in a faster website response time.

Using full-page caching as part of Magento optimization efforts can significantly increase website speed. This technique creates cached versions of your pages and delivers them to the user instead of running all the queries for each request, resulting in faster load times. However, not all pages can be cached.

To enable the full page cache in Magento 2 installation.

php bin/magento cache:enable full_page
You can also enable full page cache from Magento Admin:
  1. Go To System > Tools > Cache Management
  2. Please choose the type of cache that you wish to activate.
  3. In the Actions dropdown menu, select Enable option and click Submit
Varnish cache

Varnish is an HTTP accelerator and reverse proxy cache to manage incoming HTTP requests on port 80. It is primarily utilized for full-page caching in Magento. To enable the Varnish on Magento 2 installation based on the server (NGINX or Apache).

Redis cache

Redis Cache is an in-memory data structure for Magento Page Caching, Session Storage, and Cache Storage. To configure the Redis cache, verify its installation on the server and follow the instructions in the env.php file.

'cache' => [
   'frontend' => [
       'page_cache' => [
           'backend' => '\\Magento\\Framework\\Cache\\Backend\\Redis',
           'backend_options' => [
               'server' => '',
               'port' => '6379',
               'database' => '1',
               'compress_data' => '0'
       default' => [
           'backend' => 'Cm_Cache_Backend_Redis',
           'backend_options' => [
               'server' => '',
               'port' => '6379',
               'database' => '1',
               'compress_data' => '0'
'session' =>[
   'save' => 'redis',
   'redis' =>[
       'host' => '',
       'port' => '6379',
       'password' => '',
       'timeout' => '2.5',
       'persistent_identifier' => '',
       'database' => '2',
       'compression_threshold' => '2048',
       'compression_library' => 'gzip',
       'log_level' => '4',
       'max_concurrency' => '6',
       'break_after_frontend' => '5',
       'break_after_adminhtml' => '30',
       'first_lifetime' => '600',
       'bot_first_lifetime' => '60',
       'bot_lifetime' => '7200',
       'disable_locking' => '0',
       'min_lifetime' => '60',
       'max_lifetime' => '2592000'
Magento Full Page Cache Code Broken

Magento's Full Page Cache might break even after the above steps are followed. because of code issues. Sometimes, in XML, the developer puts the cacheable="false" to block, which causes the full page cache to break, and the Magento caching mechanism does not cache the full URL.

You can test whether your page is cached by putting the Magento site into developer mode and checking the server response headers.

  1. Open your website in the private window with the inspect element.
  2. Go to the Network tab and check the initial request's server response header X-Magento-Cache-Debug: MISS.
  3. After seeing the cache debug MISS, you can refresh the page, and if the cache debug is still MISS, then the Magento Full Page Cache is Brocken.

Search the code of layouts and remove the cacheable="false" from the block to fix the issue.

In some cases, we need that layout block not to be cached. Then, you can follow the Edge Side Includes setting with ttl as below.

<referenceContainer name="content">
    <block class="Magento\Framework\View\Element\Template" template="Elightwalk_Extension::esi.phtml" ttl="30" />

3. Magento Frontend optimization

Magento provides various options to optimize the frontend assets load time, which helps load the page faster and improve the page speed.


We need to minify the JS and CSS using the magento command to improve the performance.

php bin/magento dev/css/minify_files 1
php bin/magento dev/js/minify_files 1

You can also log in to Magento admin to do the setup

  • Navigate to Stores > Configuration > Advanced > Developer > CSS Settings
  • Set Minify CSS Files option to Yes
  1. Go to Stores > Configuration > Advanced > Developer
  2. Set Minify Javascript Files option to Yes

As you notice, we only recommended minifying the JS and CSS and not bundling or merging the JS and CSS, as merging or bundling will increase the single file size, which causes the load time for asset and page speed score to decrease.

To improve the load speed of JS and CSS, you can use CDN services like AWS CloudFront, Cloudflare, etc.


Magento uses the PHP library to resize the images as needed on the catalogue and other pages, but still, the load time of images is crucial in frontend optimization.

To improve the load speed of images, you can use CDN services like AWS CloudFront, Cloudflare, etc.

If your theme does not provide a lazy loading HTML5 attribute for images below the fold, then you can update the theme code and make sure you are lazy loading the images below the first fold.

GZIP Compression:

Hosting Provides, by default, provides the GZIP Compression. You can verify the GZIP compression by following the steps.

  1. Go to the Browser inspect element and switch to the network tab.
  2. Visit the page and check the response header content-encoding

If you are missing the GZIP Compression, you can do it per your PHP Server ( NGINX or Apache).


<IfModule mod_deflate.c>


## Enable compression for files served by Apache.
## http://developer.yahoo.com/performance/rules.html#gzip

    # Insert filter for all contents
    SetOutputFilter DEFLATE

    # Apply the filter only to the selected types of content.
    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

    # Ensure that the proxies are delivering correct content.
    Header append Vary User-Agent env=!dont-vary



## Compression

gzip              on;
gzip_buffers      16 8k;
gzip_comp_level   4;
gzip_http_version 1.0;
gzip_min_length   1280;
gzip_types        text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;
gzip_vary         on;

4. Magento Backend Config Optimization

There are some Magento backend configurations that we need to check for better-optimized Magento performance.


The Magento indexer system has two indexing methods: Update on Save and Update on Schedule; we need to ensure we are running the indexing based on Update on Schedule.

When set to "Update on Save", saving a product, attribute, or category triggers a specific index. Indexers can be resource-intensive and slow down your server.

A recommended approach for configuring the indexers is to select the "Update on Schedule" option. By doing so, you can specify a particular time for the indexers to be executed by the cron job.

Choose a time when the traffic on your website is minimal. This will help ensure the indexers do not cause performance issues on your website.

You can change the indexer mode via command.

php bin/magento indexer:set-mode schedule

Or you can log into admin and go to System>Index Management: Select all indexers, and from Actions dropdown select “Update on Schedule”

Elasticsearch OR OpenSearch

The latest Magento system provides search engines such as Elasticsearch or OpenSearch; ensure you can use one already and configure it properly.

5. Magento Code Optimization

Magento has many built-in modules we might not need based on your store's requirements. We can identify them and disable them using the Magento disable command.

Many third-party Magento modules & Magento themes have faulty code, deprecated methods, or compatibility issues with the latest stable version. To improve the speed of Magento, it is recommended to use a profiler to identify heavy requests.

The profiler helps you determine MySQL queries on a page and how many are identical. Once specified, you can combine these queries into a single one or disable the code, which helps to speed up the Magento website.

You can enable the profiler using the command.

Php bin/magento dev:profiler: enable HTML

6. Magento Upgradation

Upgrading the store helps to get the latest technology like PHP, NGINX, and MYSQL, and the code gets improved by removing the deprecated code.

Upgrading your Magento store ensures protection against potential hacking attempts by implementing the latest security patches and updates.


Magento is a versatile eCommerce platform that store owners can customize to fit their needs. Speeding up a Magento 2 shop can help owners achieve higher search engine rankings and enhance the overall user experience.

Follow these methods to speed up your Magento 2 shop. You can also implement Magento website maintenance suggestions to boost your website's speed and feel free to share your experiences in the comments section.

We hope our Magento 2 performance optimization procedures will assist you in optimizing your Magento shop. You may also utilize a cache warmer, HTTP/2, CSS-JS minification, and boost browser cache TTL in addition to our performance optimization strategies.

Switch to Elightwalk immediately and take advantage of our Magento site migration service. You can contact us if you want Magento website performance improvement and any query related to Magento website optimization and Magento Store Upgradation.

FAQs about Magento 2 Store Optimization

Why is performance optimization important for my Magento 2 store?

How often should I perform performance optimization for my Magento 2 store?

Can I implement these optimization steps, or do I need technical expertise?

Will performance optimization impact my SEO ranking?

Jayram Prajapati
Full Stack Developer

Jayram Prajapati brings expertise and innovation to every project he takes on. His collaborative communication style, coupled with a receptiveness to new ideas, consistently leads to successful project outcomes.

Most Visited Blog

Unlock The Power Of Plugins In Magento 2: A Comprehensive Guide

Get started on utilizing Magento 2 plugins with our comprehensive tutorial. Master the art of plugin building and integration to improve the functionality and customization of your e-commerce shop.

Read More
The Ultimate Guide to Creating the Best Grid in Magento of 2022

Dive into the guide to creating an excellent Magento grid in 2022. Discover professional insights, strategies, and tactics for improving the grid design and functioning of an e-commerce platform for a better user experience.

Read More
How to clear shopping cart in Magento 2

Discover a quick and simple approach to emptying your Magento 2 shopping basket. Streamline your shopping experience by learning how to easily delete things and refresh your basket.

Read More