Magento Performance Optimization Tips

Jonathan Yu

Jonathan Yu

Welcome to the “Ask Trellis Expert” series, where we tackle topics like “Magento Performance Optimization.” In this edition, Trellis’s own Senior Software Engineer, Jonathan Yu, offers straightforward, effective strategies to enhance your Magento store’s performance. Dive into simple yet powerful tips to streamline your eCommerce operations and provide a smoother experience for your customers.

This series is your go-to resource for expert advice on optimizing every aspect of your Magento site. Join us as we make Magento optimization easy to understand and implement.

a professional slide titled "Magento Performance Optimization." It features the Trellis logo and is categorized under "Development." The slide includes a profile photo of Jonathan Yu, identified as a Senior Software Engineer at Trellis. The background is a solid blue with a subtle geometric design consisting of circles and lines, suggesting a technical or architectural theme.
How to Optimize Magento Performance – “Ask Trellis Expert” Series

Magento stores could be heavily loaded with customized codes, other third-party extensions, and product images. They can slow down Magento performance if not optimized properly. Oftentimes, these issues seem minimal, and many people neglect them, but their impact can be huge.

SPEED MATTERS! In this article, I’ll show you the best tips and how to optimize Magento performance. Let’s dive in!

Magento Performance Optimization Tips

Before you optimize Magento with the following tips, please ensure it meets the latest Magento 2 system requirements:

  1. Choose Magento Optimized Hosting
  2. Update Magento to The Latest Version
  3. Avoid Built-in Cache
  4. Deploying Varnish Cache
  5. Keep Indexers Updated
  6. Disable Flat Catalog Category
  7. Perform Custom Extention Audit
  8. Optimize Product Images
  9. CSS and JavaScript Optimization
  10. Optimize TTFB
  11. Clean Database Logs

1. Choose Magento Optimized Hosting

Not all website hosting companies are equal. If you are considering Magento hosting then don’t underestimate the importance of a good web hosting service when it comes to Magento performance optimization. Choose a hosting provider who is fast, secure, and reliable. If you end up with mediocre hosting, your Magento store will eventually suffer from performance and security issues.

Price is an important factor when it comes to making a decision. Commonly, low pricing attracts us, but it comes with a huge cost in terms of time and effort since we mostly end up fixing our server issues. We recommend choosing a managed hosting provider so you can only focus on growing your business.

2. Update Magento to The Latest Version

Always keep Magento up to date! The latest Magento releases offer new features, enhance bugs, and fix bugs to improve your site’s performance dramatically. Thus, the most basic and essential tip for Magento performance optimization is to update your Magento store to the latest version.

If you are on Magento 2.2 or 2.3, it’s highly recommended you migrate to Magento 2.4 or the latest release to experience a better, more reliable, secure, and faster e-commerce solution.

3. Avoid Magento Built-in Cache

Magento 2 speed is a big concern. Many technologies are integrated with Magento 2 speed optimization, such as Varnish, Redis, Nginx, and even full-page caching solutions.

Use Memcached or Redis. Both are the distributed memory caches that speed up Magento 2 large-scale web applications with dynamic databases. They reduce the load of database requests on servers and deliver cached data if an external data request allows it.

Redis is an optional back-end cache solution to replace Zend_Cache_Backend_File, which is used in Magento 2 by default. For PHP sessions, both caches are the right choice to use. You can configure Redis to handle over 60k session connections per second.

Opting for Redis integrates a high-speed backend cache with full cache tag support and no need for additional low-level file system cache. As a result, the performance is excellent and stable, particularly in high-traffic Magento stores.

For more information on how to configure Redis for Magento, please refer to Configure Redis.

4. Deploying Varnish Cache

Varnish cache is a splendid way for Magento speed optimization if your website is heavy with content. As a reverse proxy, varnish cache quickens your speed loading page using a cached version of the site than making a new request each time the page is visited.

For more information on how to configure Varnish for Magento, refer to the following resources:

5. Keep Indexers Updated

Magento allows you to work with bulk data, reducing the load time. To overcome this, Magento needs to reindex its indexers because the core system updates indexers on every object stored by default.

Magento indexers can be set to two modes: “Update on Save” or “Update on Schedule.” The best mode to set the indexers is to “Update on Schedule.” In this way, they execute the cron job at a specific time that you set. It’s recommended you choose a time when the traffic on your website is low.

6. Disable Flat Catalog Category

By default, the enabled flat category has been an optimized option for many years. However, since Magento 2.3.x and above, Magento architecture has changed completely. For Magento performance optimization, the platform provider no longer recommends flat catalogs because of indexing issues and the risk of performance degradation.

Before disabling the feature, it is important to check all extensions required to work with the flat catalogs.

To disable Flat Catalogs:

  • Navigate to Stores → Configuration → Catalog.
  • Expand the Storefront section.
  • Set No in the Use Flat Category and the Use Flat Catalog Product fields.

On the other hand, flat catalogs still work well with Magento 2.1.x and Magento 2.2.x versions. You can shorten the reading speed of the database by enabling Flat Category and Product.

7. Perform Custom Extension Audit

This is probably one of the most important steps to enhance your store’s performance. Custom extensions can make Magento 2 heavy and sluggish.

Thus, performing a 3rd-party extension audit can give you a sigh of relief. Some custom extensions can do more harm than good.

The one that comes straight from the experts and makes your Magento faster will be the right choice, and they speed up Magento 2 development too.

Here’s how you do it:

  • Disable all the custom extensions one by one.
  • Benchmark speed with and without an extension.
  • List out the extensions that take the most time to run.
  • Contact their vendors and ask to patch.
  • In case of no patch, just remove the extension and find a substitute.

8. Optimize Product Images

The image size impacts the website’s speed. Hence you need to ensure your images are properly optimized and have a good ratio between quality and size.

In the older technique, the server downloads the content images as the page loads. To overcome this, Magento uses lazy loading, which means loading images after the page is fully loaded, or while the user scrolls through the catalog.

You can also use AWS or a CDN to deliver your content much faster. Check if your images are properly optimized and have a good ratio between quality and size.

9. CSS and JavaScript Optimization

9.1 Minify CSS and JavaScript

Merging and minifying CSS and JavaScript files can improve Magento performance optimization, as well as the website load time. Instead of sending 50 to 100 requests, the browser only needs to send just 2 (in most cases). On top of that, minification benefits the process with a smaller size of individual files.

Magento has this feature built-in, and you can enable CSS/JS minification from Magento Admin.

To enable CSS minification, go through the following steps:

  • Enable the Magento store in production mode.
  • Go to Stores → Configuration → Advanced → Developer → CSS Settings.
  • Set the Minify CSS Files option to Yes.
  • Click Save Config and Flush Cache on the System → Cache Management page.

To enable JavaScript minification, follow these steps:

  • Put the Magento store on production mode.
  • Go to Stores → Configuration → Advanced → Developer.
  • Set Minify JavaScript Files option to Yes.
  • Click Save Config and Flush Cache on System → Cache Management page.

9.2 Use Critical CSS

CSS styles define how your store pages look. However, they also definite how fast the page loads. Except for the size and location, Magento website speed depends on the order of CSS styles loading.

CSS styles from external files block the rendering of the page so the page is not displayed until these files are loaded. This causes a significant delay in the speed of page loading, not speaking about the user experience.

By using critical CSS you define CSS files that should be loaded first and those that can be deferred. This way you eliminate the render-blocking resources and improve the first meaningful paint drastically. At the same time, non-critical styles are reloaded asynchronously.

To configure the path to the critical CSS file:

  • Go to Stores > Settings > Configuration > ADVANCED > Developer.
  • Enable CSS Critical Path.

9.3 Disable JS Bundling

JS bundling should group JS files into big bundles and reduce the number of HTTP requests to the server required to load the page. However, it doesn’t improve Magento site speed, but quite the opposite.

The website page is not loaded until the browser downloads all of the JS bundles, even if the page uses files from one or two bundles. Moreover, Magento loads JS bundles every time a browser requests a new page.

And considering JS bundles are around 5-10Mb on average, this is not the best way to improve Magento site performance.

So, the other way to speed up Magento 2 is to disable JS bundling:

  • Go to Stores > Configuration > Advanced > Developer > JS Settings.
  • Disable the JavaScript Bundling.

9.4 Use Advanced JS Bundling

We don’t recommend using regular Magento JS bundling because of the inefficiency. As an alternative, use advanced JS bundling.

It allows you to reduce the number of HTTP requests to the server and decrease the size of JS files, the same as the regular JS bundling. However, advanced JS bundling eliminates the need to load all of the bundles, for all pages requested by a browser.

Each page has a certain set of requireJS dependencies. To satisfy the need of each page you don’t need all of the bundles, just a couple of them.

Therefore, to enable advanced JS bundling you need to define bundles by page types (CMS pages, product, category, checkout) or purpose (shipping features, checkout features, product-related features).

Since only some specific bundles will be loaded for one page, Magento speed will increase significantly. However, for websites with a deep module structure and many customizations professional configuration might be required.

10. Optimize TTFB

TTFB or Time To First Byte is the time a browser’s request travels to the server and the server responses back to it (latency).

This is why Time To First Byte is also referred to as Server Response Time. It is also the time when the server generates HTML.

Google suggests that your TTFB should be much less than 200ms. Otherwise, it considers it bad TTFB. Thus, the Server Response Time Audit is a quintessential task to speed up Magento 2 and rank better on Google.

11. Clean Database Logs

Despite its market share and performance benchmarks, Magento’s database still needs improvement. One common reason behind this is the space taken up by the logs. The database performance improves significantly when removed because of the decreased lag in process execution.

Note: It’s recommended to take a recent backup before making new changes to the database.
Also, Magento automatically & frequently generates new log files, so removing the old ones should not cause any problems. To set the logs time, follow these steps:

  • Navigate to the Stores → Configuration.
  • Expand the Advanced → System and open the MySQL Message Queue Cleanup section.
  • Set the specific amount of time in New Messages Lifetime to automatically clean the old log files.
  • Once complete, click Save Config.

Conclusion

Magento 2 store can be fast although it’s heavily loaded. However, it’s not rocket science to speed up Magento 2 store’s performance and boost sales. It’s as simple as practicing the given tips and tricks.

I hope this post helps you to know how to optimize Magento 2 website and improve Magento 2 performance.

Contact Trellis to talk about how you can transform your ideas into reality with our web development services.

Leave a Comment

Share this post

Related Posts

See all posts