Magento 2 speed optimization is one of the steps every Magento store owner takes when the traffic drops, bounce rates rise and there is no increase in conversion rates. All this because website performance is a vital factor that influences not only Magento SEO and traffic, but purchasing decisions.
However should you wait till the Magento speed becomes a critical matter? It’s much better to act now to ensure a fast and user-friendly environment consistently.
So, in this guide, you’ll find 23 actionable tips that will help you speed up Magento 2 and give your store the speed boost it needs.
Why is Magento Slow?
Before we dive deeper into the Magento speed optimization tips, we need to figure out why is Magento slow in the first place? It is one of the best CMSs out there which people choose for its unique functionality, exceptional features, and, obviously, speed.
Yes, Magento with sample data is really fast. But as soon as you start adding on extra functionality, customizations and third-party modules, it starts to drop. So, lets see the main reasons why this happens.
- Inadequate hosting — as we’ve told before, the hosting you choose at the beginning of your eCommerce journey might be enough. But as soon as you scale your website, you need more resources and support.Thus, speed optimization will require choosing Magento hosting that provides adequate SSD storage, RAM and SSL certificates tailored to your store needs.
- Poorly configured cache — caching transfers resource-intensive tasks away from the server. This correspondingly helps to use server resources more effectively.And since server response time hugely depends on the number of requests you send to it and the resources you have, a poorly configured cache is a problem. It will prolong the loading time influencing user experience.
- “Code-stuffed” theme and extensions — while different themes and extensions are aimed at improving your store experience, they can badly influence the website speed. They add new code and features to your store that can cause conflicts and slowdowns in the long run. If you are careful when choosing a new extension or theme for your store you prevent possible issues in the future.
These are the most common reasons why Magento is slow. However, there are still plenty of tiny things that slow down your store. To identify them you need to test your website speed. Luckily multiple free speed test tools will help with this.
You can start with Google PageSpeed Insights and GTmetrix as the most common ones. They provide consice performance reports along with tips you can use to speed up Magento.
Steps to Speed Up Magento 2
Once you know what slows down your website, you can focus on the following tips. Feel free to skip some steps and tackle the most critical issues first, according to your speed test report.
1. Update to the latest version of Magento
One of the first steps you can to speed up Magento 2 is to update it regularly. New releases come along once every three months and bring many new features, bug fixed, platform enhancements and speed improvements.
You shouldn’t neglect it and use the outdated versions since sooner or later it is going to result in major issues. Therefore, download the latest Magento version and update regularly to ensure the fast and streamlined performance of your website.
2. Change hosting provider
Magento is a complex platform that has certain system requirements to function properly. The obligatory requirements are SSL and 2GB of RAM. However, it will vary depending on your website needs.
You can choose a shared hosting that is best for beginners. However, don’t expect a fast website loading speed with shared hosting and the cheapest hosting plan with limited resources.
Make sure your Magento hosting provider offers you enough server resources to host a certain number of users and process enough server requests.
Besides, opt for hosting that provides you an opportunity to scale up. If your current hosting doesn’t satisfy your Magento needs, consider changing Magento hosting provider to speed up your Magento.
3. Audit third-party extensions
To keep up with the latest trends and stand out from the competition merchants resort to Magento 2 extensions. While they facilitate some processes, they may use a lot of resources and influence your website page loading times.
The best solution is to conduct an audit of your extensions regularly to find the “abuser” you can either optimize or remove completely.
4. Use lightweight Magento themes
You might be surprised, but your website theme can also significantly slow down your website, especially if it has a lot of widgets, sliders and custom blocks. Just imagine how much time it will take to load all of them.
So, it is bad in every sense for website users with good internet connection and a nightmare to the ones with the slow internet. Not only does it result in a bad customer experience, but can influence other Magento features and make things worse.
Before purchasing a theme, you have to make sure it runs fast on demo and test it with GooglePageSpeed for more detailed analysis.
5. Delete unnecessary fonts
When you try to provide a better experience for your customers you explore a lot of trendy designs, themes, and fonts. The last option can reduce the page loading speed even if they are not used.
Sometimes, it happens that you add some custom font to the <head> section of the page configuration file and forget about it. Regardless if the font is used or not, it is still loaded.
So, to speed up Magento 2 you can delete unused fonts. GooglePageSpeed suggests this too. You can use the comprehensive guide from Adobe for more details on removing unnecessary fonts.
6. Optimize images
Once visitors come to your website, all of the page content is loaded at once. There are a lot of images of different sizes that take some time to load, causing a delay in page and website loading in general.
Thus, Magento 2 speed optimization is not possible without image optimization. One of the best ways to do it — is through lazy loading. It is a method of loading images when they are loaded gradually, while customers scroll down the page. Lazy loading eliminates the need to load all images at once and prioritizes them.
It results in faster page loading and better customer experience.
7. Use optimized image format
Since images often take a lot of place on your server, lazy loading is not the only image optimization option to speed up Magento. You also need to ensure there is a good ration between image size an quality. So, to decrease the size of the images without much quality loss, you need to use WebP images.
It is a next-gen file format developed by Google and supported by most browsers. It allows you to reduce the file size by 25-35%, retain image quality and improve Magento loading speed accordingly.
Since WebP is a relatively new technology, Magento doesn’t allow you to add images already in WebP format to Magento. Instead, you can use an extension like Magento 2 WebP Images to convert images automatically or manually.
8. Disable flat catalogs
Magento flat catalogs were used to increase Magento website speed due to fewer SQL queries and data consolidation. It worked well for Magento 1.x.x and 2.x.x, fact.
However, it turned out to be causing the appearance of heavy dependencies and led to performance degradation and other indexing issues. That is why using flat catalogs is not a good practice starting from Magento 2.1.
So, one of the ways to improve Magento site speed is disabling them.
To disable flat catalogs in Magento 2:
- Navigate to Stores > Configuration > Catalog > Catalog > Storefront.
- Disable Use Flat Catalog Category and Use Flat Catalog Product options.
- Don’t forget to Save Config once you finish.
9. Disable JS bundling
JS bundling is supposed to 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.
10. Use advanced JS bundling
10. Use advanced JS bundling
Since using regular Magento JS bundling is not recommended because of the inefficiency, there is an alternative — 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.
11. Enable deferred JS loading
Except for the CSS and HTML, there are a lot of JS files loaded during the page load. All this contributes to slow website loading which neither customers nor merchants like to experience.
To optimize JS file loading, you can use deferred JS loading. It allows you to execute the JS script after page parsing and increase Magento website speed accordingly.
This means all of the scripts will be moved to the bottom of the page, except for the scripts you don’t want to move to the bottom.
12. Merge and minify JS/CSS files
There are some other ways to speed up Magento through JS and CSS. Magento has some built-in tools for merging and minifying JS and CSS files.
Minification allows you to keep your JS and CSS files “clean” by removing unnecessary data like comments, blank lines, etc. This enables web browsers to read them faster and return page requests to the customer faster correspondingly.
JS and CSS merging on the other hand allow you to reduce the number of HTTP requests to the server by combining JS and CSS files.
These two options are known to improve Magento site speed. So, it is recommended to apply them to the website infrastructure:
1. Navigate to Stores > Configuration > Advanced > Developer.
2. Enable the Minify Javascript Files and Merge JavaScript Files options in the JavaScript Settings section.
3. Enable the Minify CSS Files and Merge CSS Files in the CSS Settings sections.
13. 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 is influenced by 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.
The Developer tab is visible only in development mode. To enable critical CSS in production you can run the following command:
bin/magento config:set dev/css/use_css_critical_path 1
14. Turn on production mode
If you’re a developer, then you must know that there are three different Magento modes. Production is the fastest one and it should always be enabled on a live website.
Sometimes websites are not performing as expected since the developer mode is enabled. However, it is only used for debugging purposes. Make sure the production mode is enabled to speed up Magento 2 website.
Run the following commands to:
- check what Magento mode is enabled on your website
php bin/magento deploy:mode:show
- enable production mode if it is disabled
php bin/magento deploy:mode:set production
15. Use CDN
For Magento 2 stores that sell globally and target customers from various worldwide locations, CDN implementation can significantly improve Magento site speed.
CDN stands for Content Delivery Network. It is a system of geographically distributed worldwide servers that allows you to deliver content to your website users faster, regardless of their location.
It is achieved due to the CDN architecture that caches the image, media, JS and CSS files on remote servers. Then, CDN serves these files to users from the server closest to their location.
Magento has the CDN setup, but you do need to configure it manually. Today most of the web content is delivered through CDN. So, you should consider it for Magento speed optimization.
16. Move to HTTP/2
HTTP/2 is the upgraded version of HTTP/1 that delivers faster website loading speed. If HTTP/1 creates new server connections for every static file to process, HTTP/2 can do this simultaneously.
HTTP/2 processes multiple static files in one connection. This way website loads and renders faster since no time is wasted on building multiple connections.
Although most of the web servers support it by default, you can configure HTTP/2 through your CDN or web server.
17. Enable caches
Cache preloads the page content so that the server doesn’t have to generate the page every time a page is loaded and wonder how it should look like.
Sometimes, when developers or designers work on a website, they disable the Magento cache to work seamlessly. However, if they fail to enable it once they finish, it can result in slow website loading and a bad experience for your customers.
To speed up Magento 2, make sure all your caches are enabled. Sor that go to System > Cache Management, select all caches, Enable All of them and Submit.
Note: to monitor the cache you can enable the disabled cache notifications.
18. Implement Varnish cache
When you decide to go more advance with the Magento caching, you’ll come along Varnish. It is an open-source solution recommended by the Magento team. Though Magento already has a built-in full-page cache, Varnish is far more advanced.
Varnish serves as a web application accelerator that “boosts” HTTP traffic, saves bandwidth, and substantially improves server response time. Moreover, it is used to cache both dynamic and static content.
If some files are requested frequently, Varnish will cache them into RAM and prioritize them over the other files. So next time these files are requested, they will be loaded blazing-fast.
Varnish is a robust solution to Magento caching that can increase Magento website speed. However, it gets tricky with the configuration. So, make sure to set it up correctly or consult professionals about it.
19. Configure Redis
Another caching solution that comes hand in hand with Varnish cache in terms of usage frequency is Redis. It is a caching tool for the backend that allows you to store sessions and session data. It enables you to have fast access to the user statuses, settings and credentials.
Redis has a distributed data storage structure and allows servers to move frequently used page content to RAM. As a result of the in-memory data storage, Redis doesn’t require constant disk access. Due to this a number of performed operations increases and diminishes the delay in the search database or API requests.
Besides, Redis caches not only sessions but web pages, query results, and multiple frequently used objects for better Magento performance and response time.
20. Update іndexers
The architecture of Magento allows it to arrange a lot of merchant data (prices, catalog, store, users) into tables using indexers. So indexers is a way to transform and display products and categories data on the storefront.
Therefore, there is no need to calculate some specific data and make complex MySQL queries in Magento 2 continuously. You’ve got indexers for this. They are reindexed by the core system and you need to make sure they are configured correctly.
In case you see that some products don’t appear or there is a sudden drop in website speed, you can do reindex via CLI or reindex Magento from admin panel.
21. Clean Database Logs
Magento keeps thousands of MBs of data in logs with different data entries. If you don’t clean your logs, the database can grow heavy with unnecessary data and cause delays in responding and processing requests.
So, it is recommended to clean database logs to speed up Magento and reduce delay in loading. However, don’t forget to create a backup before cleaning the logs.
The list of safe log tables to clean includes:
dataflow_batch_export; dataflow_batch_import; log_customer; log_quote; log_summary; log_summary_type; log_url; log_url_info; log_visitor; log_visitor_info; log_visitor_online; report_viewed_product_index; report_compared_product_index; report_event; index_event.
22. Use Elastic search
Elasticsearch is a huge step for regular Magento catalogue searches. It provides a fast content search because the indexing service runs on the server. The system doesn’t have to search the entire database for the search query match. Thus it is a great way to speed up the Magento 2 catalogue and search pages.
If you’re using the Magento 2.4.x you have the Elasticsearch enabled by default. But if your Magento version is lower you need to go to Stores > Configuration > Catalog > Catalog > Catalog Search and choose Elasticsearch for Search Engine.
23. GZIP compression
As we’ve already mentioned, your server processed many requests at the same time to deliver content to your users. So GZIP compression is used to manage the CPU load time and decrease the bandwidth. This allows a server to provide smaller file sizes that load faster correspondingly.
However, there is a downside since you load the CPU while compressing the files. So the process takes longer as you compress the file more. The default GZIP compression level is 6 where the compression rate is higher and the speed is lower. But you can change that to suit your needs. The Level of compression ranges between 1 and 9.