Optimizing Magento 2 for Speed

by | Feb 1, 2022

Martin Pachol

Martin was the Co-founder and CTO of MageMojo which built Webscale Stratus. He has 25 years of experience in Database and Systems Administration, Software Development and Kubernetes Infrastructure. He's spoken at tech events and authored open source Magento modules used in hundreds of storefronts.

It’s no secret that speed counts in today’s Internet. Google has made it quite clear that the faster web pages render, the better it is for a website’s rankings.

For a Magento 2 website, there are three areas to focus on to increase overall render times:

  • Server hosting
  • Indexing and caching
  • Theme features

If a Magento store can master all three, they are in a prime position to capitalize on ranking performance.

Server Hosting for Magento 2

As the leading Magento hosting provider in the world, Webscale Stratus has learned—and taught a lot—about how to optimize server performance for Magento 2. The Webscale Stratus platform represents state-of-the-art scalable, cloud hosting.

The ideal server hosting environment requires much more than simply piling on RAM and CPUs; to make Magento literally pop onto a visitor’s screen, the hosting must be a fine-tuned combination of server hardware, content delivery network (CDN), caching, and network throughput.

While dedicated servers can actually deliver a stellar performance, cloud-based hosting enables Magento stores to receive the greater network bandwidth and when needed, auto-scaling to meet sudden spikes in traffic. Furthermore, cloud hosting keeps overall costs in check as merchants only pay for the actual services used, whereas dedicated servers must be fully paid for, whether or not they are fully utilized.

Webscale has created the only fully automatic scaling Magento-focused hosting platform. It took us several years and millions of dollars in research and development to arrive at such a level of performance.

Improve Speed with Indexing and Caching Tweaks

Magento uses indexes heavily to optimize database performance. The re-indexing can truly bog down a Magento store if not configured correctly. Indexing mode should be set to “Update by Schedule” instead of “Update on Save.” This allows indexing to run during the regular cron schedule, whereas if indexing occurs whenever a related record is saved, the re-indexing can truly stack up and impede store efficiency.

Beginning with Magento 2.1, enabling flat catalogs is not recommended as a best practice.

As for the cache, all caches should be enabled. With Magento 2, Varnish FPC should be enabled rather than the built-in full page cache. Redis cache should be used for both caching and for sessions. We highly recommend that no store use their database for storing session information.

Purge Database Tables

Several Magento tables can get quite large over time, which can affect database performance. By periodically purging larger tables, you can reduce database indexing routines and speed lookups.

One table you should attend to is the quotes table. This table contains a record of every shopping cart created, whether or not it converted to a completed sale. By purging unconverted carts older than, say, 60 days, you can greatly downsize this table.

Log tables created by various extensions and add-ons should be likewise purged from time to time. One common table we often find that needs pruning is the mageplaza_smtp_log table.

Theme Features

Magento themes come in all shapes and sizes. At first glance, it’s difficult to figure out which ones are truly fast and which ones are not. If you’re shopping for a theme try running their demo site through Google Lighthouse to identify any potential problems. The most common are those that prevent early rendering of the page.

One of the pitfalls you should be aware of is when you turn CSS Merging on in your store’s backend. Merging CSS and JavaScript is very useful to improve speed, but sometimes the merging of CSS can present display issues on the frontend of a Magento store. The merging of JavaScript can sometimes be problematic with certain extensions.

If you find that your theme is hindering your speed, do not be afraid to consider another theme. The loss in revenue from poor rankings can far outweigh the cost of a new theme.

These are a few of the most important considerations when optimizing Magento 2 for faster page rendering. For more information or assistance with optimizing your Magento 2 installation, please refer to our Documentation articles.

Recent Posts

Headless Commerce Drives Edge Computing Adoption

Headless Commerce Drives Edge Computing Adoption

In e-commerce today, the challenge to meet and exceed customer expectations is driving innovation. The demand for frictionless shopping, 24/7 availability, superior product and impeccable service quality is ever increasing, putting pressure on...

read more