Speed Up Your Magento 2 Store: 19 Magento Optimization Tips

Table of Content

optimize-your-magento-1-and-2-speed

Magento speed optimization is a website performance enhancement process, aimed at improving loading times and responsiveness for a better user experience. When you speed up Magento 2, your store ranks better in SERP and has a reduced bounce rate.

If you've been wondering how to achieve these benefits through Magento performance optimization, this post will provide all the information you need. Below, we talk about Magento optimization best practices – both frontend and backend – and suggest helpful tools, pro tips, and easy-to-follow configuration guides.

Why You Need Magento 2 Performance Optimization

According to Google, the chance of customers bouncing from your website increases by 32% when your page takes 3 seconds instead of 1 to load. An in-depth online performance study even shows that the optimal load times for the lowest bounce rate range from 700ms to 1.2s and load times for peak conversions range from 1.8 to 2.7 seconds. 

Speaking of conversion, here are some more facts that tie the importance of Magento 2 speed optimization to your revenue:

  • Almost 70% of consumers state that a website’s page speed affects their willingness to purchase from an e-commerce site.
  • Each 100-millisecond delay in load time hurts your conversion rates by 7%
  • A website that loads in 1 second has a conversion rate 3x higher than a site that loads in 5 seconds and 5x higher than a site that loads in 10 seconds.

Frontend and Backend Magento 2 Optimization

First, test your current Magento 2 loading speed with one of the tools we offer or request our performance audit service. If your results are alerting, you can address the issues by using a combination of frontend and backend Magento performance optimization techniques.

To succeed in making your Magento store faster, you can use several methods. All of them can be divided into two general categories:

Frontend speed optimization involves improving and adjusting Magento store elements visible to your users. This method may include:

  • Image optimization
  • JavaScript and CSS file minification 
  • Caching
  • Lazyloading implementation

Backend speed optimization techniques focus on how to optimize Magento 2 website server and reduce the number of database queries. These are:

  • Code optimization
  • Server settings optimization
  • Indexing configurations
  • Extension management 

Each of these variants has its pros and cons:

  • Caching methods will accelerate many operations and speed up requests for static and dynamic pages. But unless your code and server are optimized, caching can only do so much.
  • Server optimization can boost a site’s performance in no time while requiring relatively low investments. However, you can't expect mindblowing results if your website has code issues. Amasty experts have seen Magento stores where code issues repeatedly led to checkout failures while 3072MB were allocated for the memory_limit [sic]. In cases like these, server configurations will, at best, only postpone checkout failures for a few seconds.

  • Code optimization can help with the fundamental Magento performance issues. Yet its costs can be rather significant because the 'issues' here aren’t just 2 or 3 small coding bugs.

Now, let's take a look at all these and more speed optimization options in greater detail.

19 Proven Magento 2 Speed Optimization Techniques

You can optimize Magento for a satisfying customer experience and firm Google standing in multiple ways. In the next section, Amasty experts share the 19 most effective Magento 2 speed optimization steps.

1. Keep Magento Updated

One of the simplest and fastest methods of Magento 2 performance improvement is to stay on top of new Magento releases. Magento’s updates provide performance upgrades, patches, and other essential features and resources to keep Magento running smoothly and avoid slow loading times caused by out-of-date systems. If you’re using the latest version of the platform, you’re on the right track.  

2. Delete Unused Data

The Magento Datalog stores vital information about your products but it also stores unused data that can slow down your Magento loading time. For instance, you might have details on products you no longer sell that still take up disk space. Regularly deleting this data keeps your pages loading efficiently.

You can clean up your Magento Datalog in a few simple steps. From the Admin Panel, select System > Configuration > Advanced > System. Expand the MySQL Message Queue Cleanup option and set values for the different attributes. Save the configuration once you’ve included all the required information and are ready to proceed.

3. Optimize Your Images

Image sizes play a big role in how fast your website is and weighty images can ruin your performance. Run Magento 2 PageSpeed Insights and look at the detailed report that lists all the weightiest illustrations. To make a complete audit, use Screaming Frog's Spider. Download a complete list of all the images on your website with their addresses and weight values.

Since images are integral to selling a product, you should find a balance between image quality and size. You don’t want to lose customers by including only low-quality images, but you want everything to load quickly so customers can get a complete look at your catalog.

One of the most popular Google tips is to use JPEG 2000, JPEG XR, and WebP formats to replace the images on your server and increase Magento 2 speed. With all images compressed into WebP Magento 2 stores are especially fast. As for the weight, an optimal value for a 400px wide .jpeg photo is about 35 – 70 Kb. At Amasty, we usually recommend clients have the image’s source file resized to the optimal size instead of relying on resizing by CSS to be 100% sure they won’t cause slowdowns.    

How to Optimize All Your Magento Images in a Click?

Try out Amasty's best-seller: Google Page Speed Optimizer!

4. Use HTTP/2  

HTTP/2 is a protocol for faster web page loading that reduces latency and improves efficiency via such features as server push, multiplexing, and header compression. It uses a single TCP (Transmission Control Protocol) connection to asynchronously send numerous requests for data to your server, allowing you to download multiple files from a server in ASync mode with no risks to site performance.

Switching to HTTP/2 can achieve even better Magento 2 optimization than reducing HTTP requests. What’s more, if your website uses HTTP/2 technology and loads in under 3 seconds (the current “golden rule”), you can expect Google to boost your Magento score as a best practice follower. The protocol is currently in use by 35.6% of all worldwide websites and the trend is still increasing. 

To check if your Magento loads with HTTP/2, you can use the dev tool of your browser. Just press Ctrl + Shift + i and go to Network from the upper horizontal navigation menu. (If there’s no such a column, add it by right-clicking). If you see no HTTP/2 protocol in the column, this means it’s not there.

5. Enable Expire Headers

Using expire headers in Magento helps optimize website speed by instructing the client's web browser to cache static resources such as images, CSS, and JavaScript files for a specified period. Once cached, these resources don't need to be re-downloaded on subsequent visits, reducing the number of HTTP requests and improving page load times. 

Leveraging browser caching through expire headers not only enhances user experience but also reduces server load, resulting in faster and more responsive web pages. To enable expire headers, you can insert the following code into your server's configuration file, typically found in the Magento2 htaccess file for Apache servers:

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

6. Use Full-Page Cache 

Another way to speed up your Magento 2 site is to enable backend caching. Magento 2 offers various sever caching options, including full-page caching, block caching, and object caching

Full-page caching is particularly effective for Magento performance optimization by serving cached versions of your site pages for users, significantly improving your loading time. Block caching and object caching, on the other hand, help optimize the rendering of individual page elements and the retrieval of data from the database. 

7. Enable Varnish Cache

As an alternative to FPC, you can use Varnish cache, a powerful HTTP accelerator designed to improve the performance of dynamic, content-heavy Magento stores. Varnish Cache operates as a reverse proxy server. Rather than running individual queries for each user request and regenerating content from the Magento backend, Varnish delivers the same HTML response with no need for more queries and back-end processing, lowering your site’s network bandwidth consumption and total response time.

Upon installation, you can enable Varnish Cache in the following steps: Stores > Configuration > Advanced > System > Full Page Cache > Caching Application > Varnish Caching

8. Implement Lazy Loading

The Lazy Loading technology helps you save even more image-loading resources. Your Magento will load images only in case a user scrolls down to them. Otherwise, it will leave the unviewed elements “untouched”. Using Google Page Speed Optimizer, we’ve easily applied this method on our main page: the images of brand logos and social proof badges load and become visible only as you scroll down.

9. Choose a Trusted Hosting Provider

A trustworthy hosting provider is a massive part of optimizing your Magento store. Magento has specific prerequisites to run efficiently and properly, and not every hosting provider has the features necessary to handle a Magento store. Technical requirements include Web Services, PHP, and related prerequisites to avoid slow response times and poor Magento performance. 

Read More: Best Magento Hosting Providers

10. Use “Update on Schedule”

Magento users have two options for scheduling their indexers: Update on Save or Update on Schedule. While it might seem like a small change, updating on schedule rather than on save will consume fewer resources and help your website run faster. When your indexers are set to Update on Save, specific indexes run every time you save a product, category, or attribute, which is time and resource-consuming and runs the risk of slowing down your servers.

By setting your indexers to Update on Schedule, you can have everything updated at a specific time, such as when traffic on your site is typically slow, rather than updating when more customers are using your site. To enable this Magento optimization technique, choose System > Index Management in the Admin and select all indexers. From the Actions dropdown menu, choose Update on Schedule.

11. Re-Index Your Products

Another indexing option that can optimize your Magento website is re-indexing your products. Products that aren’t properly indexed won’t appear correctly and can slow down your website. Re-indexing these products will bring scattered data into a single table, enhancing your Magento performance.

Re-indexing is a relatively simple process. Navigate to System in the main menu and select Index Management from the dropdown. You'll see a list of available indexers, where each indexer corresponds to a specific type of data in your store. Check the checkbox next to the indexers you want to re-index and then select Reindex Data from the Actions dropdown at the top right before clicking Submit.

Alternatively, you can run the following command in Magento CLI:

php bin/magento indexer:reindex

You can also set up automated re-indexing to ensure that your store's data stays up-to-date without manual intervention. You can achieve this through Magento cron jobs configured to run the re-indexing command at specified intervals.

12. Set Up a Magento CDN

A content delivery network (CDN) will allow your Magento site to achieve faster speeds, essential to attracting and retaining customers. However, while a CDN is important to your Magento website, it doesn’t operate like your site’s cache. Instead, you’ll need to configure your CDN specifically because it isn’t already integrated into Magento. You can start the process by going to Admin > Stores > Settings > Configuration.

Once you reach this page, choose General > Web. Open the page’s Base URLs section, and enter the URL of the site location on the CDN in the Base URL for Static View Files option. Type in the URL for your JavaScript files in the Base URL for User Media Files option. Go to the Base URL (Secure) field and open it. Type the location URL on your CDN in the field Secure Base URL for Static View Files. Finally, type in the URL of the JavaScript files on your CDN in the Secure Base URL for User Media Files option and save the configuration.

Read More: How to Set Up Magento CDN  

13. Minimize Your JS and CSS

Another way to achieve Magento speed optimization is to minimize your JavaScript and CSS files. There are 4 JS optimization techniques:

  • Downloading each script separately
  • Bundling
  • Merging
  • Bundling & merging

Bundling & merging is one of the most effective because all your separate JS/CSS files can be merged into a single file. This will help you with Magento performance tuning and significantly improve Magento 2 site speed. To merge files, follow these steps:

  1. Navigate to the Admin Panel, then select Stores > Configuration > Advanced.
  2. From the advanced tab, select Developer.
  3. Locate the JavaScript settings option, then change the values of the Merge JavaScript Files, Minify JavaScript Files, and Enable JavaScript Bundling to “Yes.”
  4. Under CSS settings, change the values of the Merge CSS Files and Minify CSS Files to “Yes.”  
  5. After setting this up, click on Save Config.

If you want to take a more comprehensive approach to the task and ensure the best results, start with our free Magento Google Page Speed Optimizer. With this extension, you’ll minify HTML, CSS and JS, merge CSS and JS, move JS to the page bottom, and enable all-in-one Magento performance optimization to reduce the number of HTTP queries and their processing time. 

14. Improve Magento TTFB 

Magento time to first byte (TTFB) shows you how much time your Magento 2 needs to generate an HTML page. It is one of the main metrics of your Magento performance as it directly affects your position on SERP and is also the one that usually needs a professional optimization approach. To analyze the most time-consuming process and reduce your Magento 2 TTFB, you need to run a TTFB audit with a Magento profiler and perform a Magento TTFB optimization.  

Step 1: TTFB Audit

To reduce server response time with the Magento 2 profiler, you can set up the profiler in one of two ways: using a command or by configuring the MAGE_PROFILER environment variable. 

1. Using a Command

bin/magento dev:profiler:enable [--html] [--file]
After enabling the profiler, visit your Magento storefront or perform actions in the admin panel to trigger the profiler. Once you've captured the data you need, disable the profiler using the following command:
bin/magento dev:profiler:disable

2. Using the MAGE_PROFILER
To enable the profiler, set the MAGE_PROFILER variable to "html" or "file" depending on your preference:
export MAGE_PROFILER=html / =file
After setting the environment variable, trigger the profiler by visiting your Magento storefront or performing actions in the admin panel. Remember to unset the variable after you've captured the necessary profiling data to avoid unnecessary overhead on subsequent requests:
unset MAGE_PROFILER

Step 2: Results and TTFB optimization

Here’s the information contained in different columns of the TTFB audit report:

  • Timer ID – a unique identifier applied in the profiler function call. To identify a Timer id nested level, count the dots on the left. 
  • Time / Avg – time/an average time that the Timer ID needs to pass from the profiler start call to the stop call (in seconds).
  • Cnt – identifies the number of times the block of code was run. 
  • Emalloc – memory consumed by PHP to execute the block of code (in bytes). 
  • RealMem – all memory taken by the system to run PHP processes. It includes unused pages as well.

Pay special attention to Time and Cnt to identify the Timer ID with the most time spent and the largest number of code running. Once you’ve defined it, inspect Magento files to understand where these blocks are placed. Also, when looking for the most time-consuming Timer IDs, pay attention to those with children, as profile entries are nested and one entry’s time includes all of its children’s. 

15. Optimize PHP Server Configuration 

Your Magento performance depends not only on the version but also on the PHP configuration of the domain. Adjust server parameters such as memory_limit, max_execution_time, and upload_max_filesize or switch off the session.auto_start or mods. To do this, add the next patch of code in your .htaccess file :

php_value memory_limit 2GB
php_value max_execution_time 18000
php_flag magic_quotes_gpc off
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
php_flag zend.ze1_compatibility_mode Off

If you run Magento 2, don’t forget about OPcache, which is bundled with PHP 5.5.0 and later. The module uses shared memory to keep precompiled script bytecode and speed up your website loading. Learn why and how to use OPcache from our partner’s blog post.

16. Optimize Magento .htaccess 

In Magento, the .htaccess file is a configuration file used on Apache web servers to control various settings for the specific directory. It is crucial for controlling URL rewriting, access restrictions, and other server-related configurations required for the proper functioning of the Magento website. 

The first thing you can do to speed up Magento with .htaccess is to get rid of all the unnecessary customizations you added to the file or replace them. After that, proceed to more tasks:

  • Protect your website's bandwidth by preventing other websites from directly linking to your images or files. Achieve this by adding specific directives to your .htaccess file:
    # Prevent hotlinking of images
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourwebsite.com [NC]
    RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F]
  • Secure sensitive directories and files by restricting access using appropriate directives in your .htaccess file.
    <directorymatch "^var="" .*|^app="" etc="" .*"="">
    Order deny,allow
    Deny from all
    This prevents unauthorized users from accessing critical parts of your website.
  • Periodically review and update your .htaccess file to ensure it remains optimized and aligned with the evolving needs of your website.

17. Enable gZip compression

Magento gZip htaccess compression allows you to optimize the web pages and stylesheets before sending them to end-users. You can still easily restore the original data by unzipping the files you compressed. 

To enable gZip compression, add this code to your Magento gZip .htaccess file:

# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

18. Request Magento Speed Optimization Services

There are numerous optimization services available that can help you speed up your Magento e-commerce store. Amasty’s Magento Speed Optimization Services provide all-inclusive optimization processes, including:

  • Magento performance audit
  • Caching configuration
  • Media compression
  • Magento database and server optimization
  • Code optimization
  • Theme and style optimization
  • Third-party Magento extension optimization
  • SEO services and a UI/UX audit 

You can not delegate most of these general speed optimization best practices to the ready-made solution and need to either hire an in-house specialist or outsource the task to a proficient team.  

  • Service can fix all the problems affecting Magento performance. You are not limited to any parameters of speed optimization.
  • No need for deep technical knowledge. If you don’t know how to use extensions, it may be easier to entrust the whole process to professionals.
  • High price. Services are usually quite expensive compared to extensions.
  • Site maintenance is still on you. Although the service includes a 2-month warranty on all customizations made, you still need to check your website later.

19.  Rely on A Magento Speed Optimization Extension

The main idea of using a performance optimization extension is to speed up your store with minimal manual and maximum automated efforts. For example, with such a tool you don’t need to manually convert all your images to the WebP and shrink them to fit different devices. The extension also handles CSS/JS file minimization and lazy load setup.

  • Customizable. You can customize the extension to suit your needs.
  • Low price. If you get the extension, advanced support subscription, and training service, you will have the extension installed and configured on your Magento.  
  • Built-in diagnostic. Our plugin comes with a built-in diagnostic tool that will help you monitor your website performance without any external help.
  • The extension deals only with the main issues. It can not solve problems with, for example, your server capacity or other issues affecting your Magento speed.   

Magento Speed Optimization Services vs. Extension: How to Choose

The 2 last options we’ve just offered – page speed optimization extension and optimization service  – have a huge difference in price and impact on your website. Let’s consider their best cases and try to understand when it is better to use the service and the module.

When to Go for a Magento Speed Plugin

To understand if the extension is enough to help you with speed optimization, you can go to Google PageSpeed Insights and test your website. You will get a list of parameters that Google recommends you to tune for better speed and SEO performance. Google Page Speed Optimizer can address the following warnings:

  • Optimize images automatically.  
  • Minify HTML, CSS, JS, and merge CSS and JS.
  • Move JS to the footer.
  • Sign static files to make your customers see the freshest version of your styles.
  • Enable lazy load to save resources on loading off-screen images.
  • Save and index order data asynchronously.   

From our experience, these issues are the most common among new websites and stores with little to no customizations.

When to Go for a Magento Performance Service?

An optimization service is usually more suitable for larger stores, websites with a lot of customizations, and sites that need improvements on the server side, like the caching settings. Here are the typical warnings from the Google PageSpeed Insights report that can be solved as a part of the optimization service:

  • Reduce initial server response time
  • Remove unused CSS
  • Enable text compression
  • Use video formats for animated content
  • Preload key requests
  • Preconnect to required origins
  • Avoids an excessive DOM size
  • Eliminate render-blocking resources (CSS part) 

Most of these warnings require a lot of manual work and custom development.

Of course, the final choice between the extension and service is up to you, but we hope that now you can make an informed decision.

Summing Up: Key Magento Performance Optimization Tips

Here's what we've discussed in the article and what you can do to accelerate the speed of your Magento:

  • Enable browser, full-page, and Varnish caching.
  • Optimize and compress images, implementing their lazy load.
  • Delete unused data and minify CSS/JavaScript files.
  • Leverage HTTP/2, use a reliable hosting provider, and set up a robust content delivery network (CDN) to deliver static assets faster.
  • Optimize .htaccess file, PHP server configuration, and indexing settings. 
  • Consider benefiting from professional Magento performance optimization services or extensions.

Amasty provides advanced Magento services and solutions to ensure your Magento store runs smoothly! Check out our success stories of speeding up our own extension and a home decor website, achieving under 1-second load speed. 

April 21, 2020
April 23, 2020
April 16, 2020
Comments
amine Dahimene
December 29, 2020
I think there is a code missing because you said "To enable the headers, insert the next code:" but there is no code after that paragraph? can you please let me know if there is any code missing. Thank you
Reply
Polina Kratovich
January 22, 2021
Hello there! Thanks for your careful reading. Here is the code you were looking for: <ifModule mod_expires.c> ExpiresActive On ############################################ ## Add default Expires header ## http://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>
Mark Richard
May 24, 2022
How to Optimize Your Magento 1 & Magento 2 Speed 1. Defragment your server 2. Install a CDN 3. Use the right hosting provider 4. Use Redis Caching 5. Optimize your images 6. Utilize browser caching 7. Speed up JavaScript and CSS rendering 8. Upgrade your Magento version 9. Use a web server with PHP 7+ and HHVM 10. Remove unused modules
Reply
Leave your comment

Your email address will not be published

This blog was created with Amasty Blog Pro

This blog was created with Amasty Blog Pro

© 2009-2024 Amasty. All Rights Reserved.