How to Improve Magento Performance

Bees don’t waste their time in explaining to flies that honey is better than shit. A real businessman with a future vision predicts the current need and future demand and takes the required action without wasting time in unwanted analysis and explaining to employees why the change is required.

If your website takes longer than 3 seconds to load, approx 40% of your visitors will abandon your site and will switch to your competitors. Website speed is directly linked to success and revenue and there are many reasons behind the slow page loading. It could be Cyber Monday, holiday season, promotion deals, website built in the older version, and many more that why optimized Magento installation is important for every Magento store.

Magento following the Cadence has updated its version to meet the future demand and provide new features and functions to its users. There are several eCommerce Magento 2 stores that are not performing well as they should and here is where Magento 2 performance optimization plays a vital role in finding the bugs and fixing them to boost your work speed, page speed, and ultimately customer engagement.

You choose Magento as an eCommerce platform for online business because of its one of the widely used CMS for eCommerce business today. Magento as a platform is very robust with a high level of functionality and customization options. It is highly scalable, that means one can start with small online e-commerce business with it and later on can scale up.

According to BuiltWith, 16% of the top 100,000 eCommerce websites are using Magento, 22% if we also include Magento Enterprise. And WooCommerce comes in at a close second with 12%.

Caution: – When Magento is not set up correctly, it will run slowly since it is a ‘heavy’ eCommerce CMS system.

If you run an online eCommerce store based on Magento or work as a Magento developer then this post will help optimize Magento performance and speed up Magneto store pageload speed.


Benchmarking – Whether you are a newcomer, seasoned online retailer, experienced online store owner or Magento developers making an educated decision is the best approach. Balancing the server resources to match customer demand can be a cost-effective way. Often small changes in the server settings might have an impact on the server performance and the customer experience.

Test the speed of your website across all devices

It is better to test the speed of the website pages before Magento speed optimization as testing will enable you to know how fast your page loads? How long does it take? 2 seconds? 10 seconds? Whatever it takes.

There are several tools that you can use to test page speed. Tools enable you to observe loading time, identify the main problems to resolve, compare websites to your competitors, and monitor progress.

Many tools can be used to test your Magento page loading time from which we have listed down a few:

  • Dareboost
  • GTMetrix
  • Pingdom Tools
  • Google PageSpeed Insights
  • Yslow extension
  • Quanta

Each of the tools has its skill and capabilities. When testing a site it is important to check from all aspects that include all browsers, locations, devices, hosting provider, and more.

When you are using any of the tools to perform the test of the website, these tools allow you to test all that you should know about be it cross-browser loading and speed performance testing, Various GEO Locations, and devices (PC, mobile) and you can get the detailed result in seconds.

Steps to Improve Magento Site Performance for Magento Website Owners

Magento store owners can follow these tips on how to optimize Magento store/website.

Upgrade to the latest version

Magento offers the easiest and smoothest implementation ever offered by any other provider. Keep these benefits intact by upgrading to latest versions. The latest versions come with a more sophisticated option for bug fixing, website optimization, speed optimization, security, and others.

More Magento Resources:
Magento 1 To Magento 2 Migration Process and Steps


Cache Management

Magento’s cache management system is an easy way to improve the performance of the site. But probably it is one of the least understood parts of Magento.

In Magento we have the following cache types:

  • Configuration (non-layout XML files)
  • Layouts
  • Translations
  • Collections Data
  • EAV types and attributes
  • Web Services Configuration
  • Blocks HTML output (Page blocks like headers, footers, and callouts)

When the number of products in the catalog is more than 20,000 or 30,000 then there is approximately an equal number of cache records! Reducing the number of reading operations by keeping trimmed and clean cache is one of the easiest ways of improving store performance.

Magento Content Delivery Network Integration

Slow Magento websites may cost sales. Integrating Magento CDN reduces congestion and dramatically improves access speeds of the website for customers, no matter where in the world they’re located.

To configure a content delivery network:

  • On the Admin panel, click Stores. In the Settings section, select Configuration
  • Select Web under General in the panel on the left
  • Open the Base URLs section, and continue with following:

  • In the Base URL for Static View Files field, enter the URL of the location on the CDN where static view files are stored
  • In the Base URL for User Media Files field, enter the URL of the JavaScript files on the CDN
  • Open the Base URLs (Secure) section, and continue with following:

  • In the Secure Base URL for Static View Files field, enter the URL of the location on the CDN where static view files are stored
  • In the Secure Base URL for User Media Files field, enter the URL of the JavaScript files on the CDN
  • When complete, click Save Config

Other eCommerce Resources:
Syspro ERP & Inventory Integration Benefits
eCommerce Website Vs. Marketplace

LiteSpeed Enterprise web server

Replace Apache web server with LiteSpeed Enterprise web server. LiteSpeed offers a 50% 

Steps to Improve Magento Site Performance for Magento Development Agency/Developers

There are several methods to increase Magento’s frontend performance, ranging from Magento admin panel or Magento development to server or the web hosting configuration, the most commonly missed tweak by many Magento store developers.

.HTACCESS Optimization | Enable Apache Served Files Compression (Gzip)

This technique will enable the Apache HTTP Server mod_deflate module, which through its DEFLATE output filter will compress common text-based content types (including HTML, plain text, XML, CSS, and JavaScript elements) from the server before being served to the client’s browser over the network. This results in a smaller and more efficient download size, often achieving compression rates as high as 70-90% for larger files. To enable this file compression, simply uncomment the following lines within the .htaccess file (or, add them if not already present):

<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

# 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>

.HTACCESS Optimization | Add Default Header Expire

Web browsers make use of a cache to reduce the number of HTTP requests required to download a page and render it; thereby enabling those cached Web page elements to load faster on subsequent visits. Browsers make use of Expires headers to determine for how long a component can be cached. We recommend the following settings:

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

ExpiresActive On
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType image/jpg “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType text/plain “access plus 15 day”
ExpiresByType text/html “access plus 1 second”
ExpiresByType text/css “access plus 1 day”
ExpiresByType text/javascript “access plus 1 day”
ExpiresByType application/x-shockwave-flash “access plus 1 day”
ExpiresByType application/x-httpd-php “access plus 1 second”
</IfModule>

Merge CSS and JavaScript Files

Magento 2 actually has a built-in feature to concatenate (merge) CSS and JavaScript files into one file. This will reduce the total number of HTTP requests and in turn help speed up the loading of pages.

Navigate to “System” → “Advanced” → “Developer.”
Under “JavaScript Settings” and “CSS Settings” change the drop-down to “Yes” and click on “Save Config.”

After combining these files, clear the cache. Follow the process we mentioned earlier.

Clean Up Magento Database & Logs

For Logs:-

By default, Magento keeps logs up to 180 days. This can result in database growing quite large. Change it to something smaller like two weeks (14 days) to save space.

Navigate to “Stores” → “Configuration” → “Advanced”→ “System” → “Log.”

Under “Save Log, Days” change it to 14 days, or whatever is preferred.
Click on “Save Config.”

For Optimize database by execute following sql query in database:-
Let‘s execute this SQL to clear and optimize them
SET foreign_key_checks = 0;
TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
TRUNCATE catalog_compare_item;
SET foreign_key_checks = 1;

Implement Full Page Cache Extension

Speed up Magento stores using cache to the full. Decrease pages time load and improve user experience, which leads to a better conversion rate and higher search rankings.

  • Magento loads pages much-much faster
  • A huge decrease in server load
  • Better search engine indexing and higher rankings
  • Dynamic blocks / “hole punch” support
  • Includes cache crawler!

Code Optimization
For Instance,

a) SQL queries inside a loop

Very common bad practice is to load Magento models and process it inside a loop. Running SQL query is a very expensive operation, and doing it in a loop tends to make it even worse. Instead of doing that we could use data collections to load models and then process it. We also need to be careful when working with a collection to do not exceed memory.

Wrong Practice:
foreach ($this->getProductIds() as $productId){
$product = Mage::getModel(‘catalog/product’)->load($productId);
$this->processProduct($product);
}

Good Practice:
$collection = Mage:getResourceModel(‘catalog/product_collection’)
->addFieldsToFilter(‘entity_id’, array($this->getProductIds()))
->addAttributeToSelect(array(‘name’));

foreach ($collection as $product){
$this->processProduct($product);
}

b) Models loading

We need to remember that each time of executing load () method, a separate query will be executed on a database.

Also, loading multiple models separately slow down our code. Models should be loaded only once, with a single SQL query.

Wrong Practice:
$attr = Mage::getModel(‘catalog/product’)->load($productId)->getAttr();
$sku = Mage::getModel(‘catalog/product’)->load($productId)->getSku();

Good Practice:
$product = Mage::getModel(‘catalog/product’)->load($productId);
$attr = $product->getAttr();
$sku = $product->getSku();

Consider using new HTTP/3 and HTTP/2

HTTP/2 is the new standard that all hosting providers use these days and enables it for sites that are hosted on their servers. HTTP/2 is significantly faster and allows you to achieve speed wins up to 15% compared to the older version HTTP/1.

Majority of eCommerce and other websites are using HTTP/2, especially Magento 2 websites use HTTP/2 to make the network request as it allows quicker connection establishment, allows your metrics and performance score to improve, reduces the latency and some more improvements are made that are listed below:

1) One Connection at a time:
HTTP/2 allows only one connection at a time, accepts one connection when requested to prevent round trips, and allows 2nd connection only when the first request is closed to open the website. This helps in loading the website faster.

2) Multiple request balancing:
HTTP/2 is fully multiplexed and sends multiple requests between browsers and servers at the same time over a single TCP connection that ensures faster page loading and a fairer spread of network resources.

3) Server push:
It allows the server to “push” responses proactively to a client for future use.

4) Dependent Levels:
HTTP/2 reduces additional round trip times (RTT), request are sorted on high-priority resources that mean the website loads faster with less optimization.

5) Binary:
HTTP/2 is binary that allows the information to travel fast without translating to computers native language, more compact, and is less susceptible to errors.

6) Header Compression:
HTML headers are data-heavy and HTTP/2 uses HPACK compression which reduces overheads and allows sending data between browsers and servers in a single trip.

HTTP/2 rules over HTTP/1 to fulfil the missings that were needed. However, HTTP/2 has some cons and limitations like it does not support opportunistic encryption or TCP head of line blocking and these limitations of HTTP/2 restrict website owners from getting more customer engagement.

Looking at the limitation and priority need, HTTP/3 got introduced with the improvement that was missing, increasing performance from HTTP/2. It supports the 0-RTT that makes the HTTP/3 websites first-byte time 12.4% better than the websites based on HTTP/2.

Choose dedicated Fast Hosting

A Magento site is a heavily loaded site that gets even more loaded with the structure, images, themes, millions of product images, and more which can not be run on a cheap server hosting plan or a shared hosting. If you choose the cheap plan or a shared one, this could lead to your site loading slowly and you will see 50 to 80% of the users abandoning your site.

It is strongly advisable to choose lighting dedicated fast Magento web hosting to offer your users a good experience and in addition, it also enables you to handle several back-end processes faster.

Allow Varnish Cache

It’s not the only reason behind the slow page loading time. There are several reasons and each has its practices that need to be implemented to fix the issue and speed up the Magento site. Varnish Cache is one of them.

Allowing Varniche Cache or enabling it can help you speed up your Magento website.

Let’s check how you can enable it:

As shown above, in the image, you have to log in to your Admin Panel and from the Admin panel, go to Store > Configuration > Advanced. Under the Advanced tab, you have to click on the system which will bring the option of the Full Page Cache section. This is the section where you can change the Caching Application field value from Built-in Cache to Varnish Caching.

Upgrade to PHP7

Magento is built on top of the Zend Framework, which is a popular PHP framework that allows developers to create scalable Magento eCommerce store.

PHP had a major update that is 8.0.6 released on 6th May 2021 that is part of PHP version 8 which comes with several improvements and runs faster than the earlier versions. Check with your system administrator if your Magento 2 Website is run on the latest version. If not, hire Magento experts who can help you in upgrading to the latest version which will improve store performance.

Magento MySQL Optimization

As suggested above, the Magento eCommerce website needs a dedicated or managed hosting plan, and when you have that you need to implement one step of optimizing MySQL of the Magento store.

The very first step you should be to to collect DB statistics using the little Perl script – mysqltuner.

Once you perform that, the system itself will guide you with the following steps that need to be taken right at the bottom.

You need to set my.cnf configuration variables and to do that you have to go over to variables to adjust the part and set it accordingly.

Perform 3rd-party Extensions Audit

Being Developing Magento eCommerce stores for 10+ years and also rescuing many and when we hear a bell on our door from a client about the slow performance and page load time is highly slow the very first answer I have for them is to fix custom extensions, audit them or simply remove them as they are the one that is the main cause behind the slow performance of the Magento store.


This is the first step that everyone should perform before starting Magento Site optimization services.

80% of the Magento store’s speed problems are solved with just a third-party extension audit. Thus we recommend starting with extension audit and plugin audit.

Extensions are either customed or bought from a third party that is coded by the inexperienced developers intending to have their product perform well with maximum features but 99% are non-compatible with the Magento stores and limits the site from performing better, loading fast which results in 70% of the site abandoning customers and switching to competitors.

It is normal these days that custom and third-party extensions make your Magento slow.

Here is what I usually do:

  • Disable extensions one by one
  • Find those that take more time to run and react
  • Record site speed with extension and without extension.
  • Contact the creator of the extension and ask them to fix and patch
  • If they say no way to fix and patch, find an alternative or simply disable or remove it

Use Lightweight Theme

Theme sizes directly affect your store and add more weight to its structure which results in slow loading. Hence, always use a theme of small size that will have fewer data which will reduce the load time and deliver a better response to users by loading the requested page faster.

Bug-Free Extensions

There are many extensions available in the market. You should be precise when opting for an extension for your Magento store as it is directly going to affect your store’s performance.

We recommend buying extensions from the reputed agencies, too, reading all terms and conditions, and reviews given by the existing users.

We first recommend not integrate any third-party extension but if there is no way then buy from the trusted source so that you can get better quality of extensions.

Why Should I Care?

As mentioned in the beginning, Magento site speed is directly related to the success of the business. The faster the page loading will be the higher the customer will visit, stay, engage, and will make a purchase that means the ultimate goal of making maximum revenue can be achieved.

It is recorded in the studies that 47% of the customers abandon the site just because the site loading too slow. Now calculate this in this way, 47 customers out of 100 leave your website without visiting and seeing what you have for them.

You spent money, time, energy, vision everything to please your customers but before they see all that, they are forced by the slow speed to switch to your competitors.

You should care about how to increase Magento website speed because:

  • It improves search engine rankings that increase traffic and clicks through rates
  • Gives the user a positive experience
  • Reduces load on the server environment
  • Loads your website within 2 or 3 seconds.
  • Prevents you from getting penalized by Google due to slow loading time.

Image Optimization

Optimizing product images can dramatically increase the speed of pages as this decreases their download times. Compress images (save for web) before uploading them using a tool like Photoshop or there are a number of extensions can be used to auto-optimize them.

For the mobile site, always declare width and height for them. The recommended image dimensions for mobile Magento store are:

Product image – 250px / 250px
Thumbnail – 120px / 120px

Don’t make the dimension larger and make sure that all product images are of the same dimensions for height and width.

Enable Flat Categories and Products
In Magento admin, (top menu) System > Configuration, (left nav) Catalog > Catalog, (main page) Frontend.

Set “Use Flat Catalog Category” and “Use Flat Catalog Product” to “Yes“.

The above settings will help increase the performance of Magento website. Do you have another way to speed up Magento that we missed? We would love to hear about it below in the comments.