Regarding our previous topic about Magento performance optimization, website speed has a significant impact on online businesses. Both direct and indirect impacts can hurt your sales. On the first hand, customers have a bad experience on the website and never come back. On the other, slow-loading speed is a big minus in SEO that can downgrade your web’s ranking.
For those whose Magento speed is not optimal, the Magento Performance Tuning series is the cure. This series includes:
- Part 1: Simple tips to Optimize your Magento website from the backend
- Part 2: Take your website performance a step further.
We’ve all tried to make our Magento 2 website speed as fast as possible, but sometimes the problems aren’t so simple that we can resolve them in the backend. And a slow-performing website has potential damage to your business as it affects the user experience, and influences your SEO ranking.
In this latter part of the 25 tips for Magento Speed Optimization, we will continue with the last 13 tips. Some of them are more technically demanding and are suitable for business with developers in their team to handle Magento performance tuning.
If you run in trouble with the Magento website’s speed up process or lack the resource to better performance of Magento 2 websites, then:
START your consultancy with Magento 2 Speed Up Consulting Package and SPEED your site with ease!
25+ Magento Performance Optimization Tips You Should Not Ignore (Part 2)
13. Consider using new HTTP/3 and HTTP/2
HTTP/2 was introduced in 2015 based on Google and quickly adopted by the majority of Magento websites due to its optimization data transfer, which makes HTTP/2 significantly faster than HTTP/1.
HTTP/2 primary focus on reducing the latency, and they have made some improvements:
- Single Connection: Only one connection is used to open the website, and that connection is maintained until the website is closed. This’s a big step up from HTTP/1.1 because it reduces round trips needed to set up multiple TCP connections.
- Multiplexing: Multiple requests are allowed on the same connection simultaneously. On the older version, each transfer will have to wait until other transfers are completed.
- Server push: The server can send some additional information to a client for future use.
- Dependent Levels: The requests are assigned on level dependencies, which means the server can sort out the high-priority resources and deliver them faster.
- Binary: Makes HTTP/2 easy for the server to parse, more compress, and less-error prone. It saves time for the computer since it doesn’t have to translate the information back to their native language.
- Header Compression: HTTP/2 using HPACK compression, which reduces overheads.
Despite bringing significant improvements to website performance, HTTP/2 still faces some criticisms, such as not supporting opportunistic encryption or TCP head-of-line blocking. That’s when we look at HTTP/3.
Even though still in the draft state, HTTP/3 includes new changes that promise to deliver Magento optimize speed. It has an advantage in increasing performance from HTTP/2, especially with fetching multiple objects at the same time. With HTTP/2, any interruption (packet loss) in TCP connection block all streams, and leads to the TCP head-of-line blocking problem, while for HTTP/3, due to it being UDP-based, a packet drop would only affect one stream, not all of them.
Furthermore, HTTP/3 supports the 0-RTT support, which, according to the results, makes HTTP/3 website first-byte time at 176ms, compared with 201ms with HTTP/2 would be 12.4% better!
Because HTTP/3 uses QUIC, a new protocol, it also has a slightly faster speed in smaller size websites, but with larger zones, the fine-tuning HTTP/2 has an edge.
There are also other strong points that make both HTTP/2 and HTTP/3 shine and will help your site gain a significant performance boost.
Fortunately, 99% of the Magento web hosting server will support HTTP/2, and you can ask your hosting provider if HTTP/2 is enabled in their server setting.
14. Use Progressive Web App (PWA) for Magento performance tuning
PWA stands for Progressive Web App, which uses cutting-edge technologies in mobile application development to design patterns and provide reliable, fast, and engaging, friendly user experience websites.
PWA has apparent reasons to be a perfect tool for Magento performance tuning. First, it creates an excellent browsing experience, with instant loading, quick response time, and impressive speed thanks to service workers’ help and a client-side storage API.
The second reason for using PWA is space-saving for users’ smartphones. They can call your site using a browser, and still experience natural designs and effects similar to mobile applications.
Finally, as a result of being similar to the mobile app, PWA will have particular benefits for ecommerce users. It would get users more access to the store by allowing them to pin the store on the home screen with push notifications, which get your customers to engage more with your business. It also increases the conversion rate substantially by providing speedy, secure, optimized Magento performance tuning websites.
You can follow this Magento document to develop, deploy, and maintain your PWA storefront. In case you don’t have much technical\ knowledge to deploy PWA for your Magento 2 performance tuning, you can contact a PWA Provider to set it up for you.
LEARN NOW all about Magento 2 PWA and REVOLUTIONIZE your website to the mobile era!
15. Expires Headers or Cache-Control Headers
Before we know how the Expires Headers and Cache-control Headers can help in Magento optimize speed (Magento performance optimization), we have to understand what they are and how they are used.
Expires Headers decided whether the browser should request a specific file from the server or take it from the browser cache. Expires Headers operates with the idea that it will reduce the downloads on the server (avoid downloading identical files that would cause cost more time) and also reduce the number of HTTP requests to the server.
Cache-control is an HTTP Header that’s used to specify browser caching policies with both server responses and user requests. The policies will determine how and when the website is cached and set the maximum age before expiring.
Once it expires, the browser will refresh the version by sending another request to the server. It’s the usual practice for caching static resources.
Using the Expires Headers and the Cache-control Headers, it’s possible to centralize the number of HTTP requests and compress its size, making Magento websites load way faster.
To find the config for this feature in the Magento backend, follow this path and the guide from Magento: Stores > Settings > Configuration > Advanced > Developer > Static Files Settings.
16. Remove Unused Scripts and Move the rest to the bottom.
You have done most of the tips above, but your Google PageSpeed Insight website scores still need a little more Magento 2 performance tuning? Then try to look through some code audit. Remove unused scripts and put the rest to the bottom of the page. That way, your site will load faster than before.
The reason for this change in performance is because, during the process of page loading, the browser will read the code from top to bottom, and then wait for specific JS files to download before going further.
Of course, the process is more complicated than that, but the result is still the same: your website prolongs the loading time waiting for its component to download while your customers are frustrated and abandon the cart.
Magento does have the option in the backend to put JS files to the bottom of the page; you can access by going to Store > Configuration > Advanced > Developer, then toggle Yes in the Move JS code to the bottom of the page section.
II. Take Your Website a Step Further
If you want to push your Magento website further optimized, then you can take a look further at the following tips. They will instruct you further into the technical details to get the job done, and the risk you might encounter. Still, we don’t go too deep into the professional step-by-step process, you can rely on your developer team, or your speed optimization specialists to execute the tips.
17. Review Page Performance With Magento Profiler
Magento Profiler is a Magento built-in tool that will inspect the database table, page loads, dependencies, event logs, etc.
The Magento Profiler will help you with Magento speed optimization because you can use the tool to spot bottlenecks that cause your website to slow down and fix them.
This section should be considered after you have already made sure that your hosting and infrastructure have been upgraded (mentioned in part 1) because the hardware should be the backbone for performing Magento performance tuning on your software. It’s double the edges to have the most performance-optimized page run on the best software and hardware system.
The Magento Profile is turned off by default and to turn on, go to .htaccess and add the following line:
SetEnv MAGE_PROFILER <type>
The <type> can be “csvfile” or “firebug” or “html”.
In the case of “csvfile”, you can find the report in var/log/ dir.
Another way you can enable Magento Profiler is through CLI command, type:
php bin/magento dev:profiler:enable <type>
where, <type> can be “html” or “csvfile” or “flagfile”.
In the case of “flagfile”, a flagfile named as profiler.flag will be created inside var/ directory.
If you don’t set a type and still run the command, it will put ‘html’ by default. When working with the load table, pay attention to the large values in Time and Cnt column. The Time column indicates the time a block of code took in execution. The Cnt column, which stands for “count”, is an integer value that shows how many times the code block got executed.
By looking at these two columns, we can identify which code block in the database is slowing the system down.
18. Use Lazy Loading for Images
Loading images on a page can make a significant difference based on the approach you choose, and it boosts your site without much effort.
Lazy loading can help you load images, gif, and other media sources as the user scroll down. Because the browser doesn’t have to load all information down at once, but only the prioritized content, it lightens the site loads and reduces the time it takes to process the page.
First, Lazyload will show a low resolution of the image. Then, it will quickly switch to the high-resolution source image.
For Magento, if you want to use LazyLoad on your store, but doesn’t have much technical knowledge, then:
CATCH UP sites speed using Magento 2 Lazy Load just by clicking “Yes”, “No” on the backend!
Note: From Magento 2.4, merchants can now use Lazy Loading on their Magento website. So if you’ve upgraded to Magento 2.4, check this Configuration Theme Properties.
19. Use HTML <picture> Tags
The HTML <picture> tags are suitable for images and responsive design webpages. Using this <picture> tag, you can define multiple image sources within a single <picture>. The suitable image collection will depend on the viewport and min-width parameter of the image.
You would want this because the browser will be able to adapt the image dimensions on different screens, such as mobile and desktop.
But, it does consume-time to apply the <picture> tag for the whole website, and you should make sure that your extensions can work well with it. However, the results would be a faster, more responsive site on all devices.
20. Replace Apache with Nginx
Another tip in Magento performance tuning is to replace Apache with Nginx. Sometimes, the problems can come from the webserver side. If multiple requests come from the platform, the webserver needs time to process them, which will produce downtime.
So, for Magento speed optimization, you should use the webserver that can deliver better and more efficiently the PHP and static content.
Magento 2 Devdocs software-recommendation suggests Nginx and many web hosts recommend Nginx as an optimal solution to serve both static and dynamic content while handling an enormous number of requests.
21. Clean Database Logs
For the newly built Magento platform store, there is not much to worry about logs, but as your Magento store gets older, the database logs can bottle up to hundreds of MBs and millions of data entries. These logs cause your Magento website to slow down significantly over time.
While there is an option to clean database logs via the admin panel in Magento 1, the same useful feature for Magento performance tuning is nowhere to be found. According to this Magento discussion, there has been no news of this feature coming from the developer team.
So either you could get creative, or you can download this module from GitHub, install it and follow the following instructions:
If the cleaning logs module doesn’t work out for you, then you can always contact an expert, or have your developers’ team come up with the solution.
22. Configure Redis or Memcached
Redis is an in-memories data structure store that is used as a database to improve speed on both the backend and frontend of your shop.
It’s also a separate upgrade from CDN or Varnish since it optimizes session storage, enables on-disk saves, and levels up the website stability, which makes it fast and reliable.
From Magento 2.0.6, you can use either Redis or Memcached for session storage, but not both. Memcached is a worse alternative for Redis, but we still present you with both options in case you need to use Memcached for specific reasons.
Install & Configure Redis for Magento 2
Most Magento hosting providers would install Redis for you, and the default setting server is fine most of the time. Still, if you want to perform Magento 2 optimize speed, we recommend you take a look at the manual configuration.
There are two ways you can go about Redis Cache manual configuration: Either run a command that automatically updates the env.php with the correct details, or you can manually change the env.php file.
The example command line enables Redis default caching, sets the host to 127.0.0.1, and assigns the database number to 0. Redis use default value for all parameters:
bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0
If you want to set your database to 1, then the example command line would be:
bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1
As a result, Magento adds lines similar to the one below in <Magento install dir>app/etc/env.php:
'cache' => [ 'frontend' => [ 'default' => [ 'backend' => 'Cm_Cache_Backend_Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'database' => '0', 'port' => '6379' ], ], 'page_cache' => [ 'backend' => 'Cm_Cache_Backend_Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'port' => '6379', 'database' => '1', 'compress_data' => '0' ] ] ] ],
With Magento 2.3.5, it is recommended to use the extended Redis cache implementation: \Magento\Framework\Cache\Backend\Redis.
'cache' => [ 'frontend' => [ 'default' => [ 'backend' => '\\Magento\\Framework\\Cache\\Backend\\Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'database' => '0', 'port' => '6379' ], ], ],
If you want to configure by editing in the env.php manually, then you can investigate further instructions from Magento 2 Devdocs. You can look at one of the samples of the complete env.php file with Redis enabled for your reference.
23. Remove unused Magento 2 plugins and event observers.
Even though both observers and plugins have been around for some time, Magento 2 is now moving away from observers and encouraging developers to use plugins instead.
Observers used to be the primary means of injecting changes to code logic, but now this is the prerogative of dependency injections and plugins. Event observers used to be the legacy tool of Magento 1, but there are limits to what it can do.
Plugins are more versatile than observers, and they can function anywhere in the system, used to change or override any public method in Magento. They’re valuable tools for custom development.
However, right now, both tools are both in the system, which can interfere with Magento 2 performance tuning, slowing the platform down. So the tip for Magento 2 optimize speed here is removing the unnecessary event observers to speed up Magento pages.
All core observers and their corresponding tags are shown in the events.xml file located at /dev/tests/functional/etc/.
To disable an observer, add:
to its code. Overriding plugins works similarly, but you should check your Magento installs carefully to see which plugins are necessary and which one you can safely override or turn off.
Warning: This should only be your last choice, as for extension use, the removal of plugins/ event observers might compromise some core functionalities of the custom extensions, and even when you call on the unused ones, it’s still hard to control which one Magento created.
24. Inspect Third-Party Extensions
Your platform can also be degraded if you use multiple extensions of third parties, as they can affect your performance by overloading the system.
In this case, the only thing you can do is using Magento Profiler to remove the possible extension that’s causing performance degradation.
You can also check the Module folder that located /app/etc/modules to make sure that no unnecessary bloats are dragging your website down.
25. Switch Magento 2 to run on Production Mode
To improve Magento website performance and user experience, we recommended you switch mode to production mode when there is no need to fix code lines. You might think this tip is unnecessary, but you would be surprised how easily people forget to switch mode after setting something or having a new install.
Magento 2 comes with four modes: Default, Developer, Production, and Maintenance Mode. On Magento Cloud, there is Maintenance and Production Mode only.
The Default Mode is the one that automatically applied if no other were specified. Default Mode allows you to deploy the Magento application on a single server without changing any setting. However, the Default Mode is not ideal for Magento performance tuning, because it’s not optimized for production.
The Developer Mode is suitable to run for fixing, extending, or customizing the platform.
The Production Mode is optimized for performance, and it’s the one you would want to use for customers visiting your store since it brings out the best user experience.
The Maintenance Mode takes your site offline when you are maintaining, upgrading, or configuring your platform. Once the site enters Maintenance Mode, customers will be redirected to the Service Temporarily Unavailable page.
To display the Current Mode your Magento is in, and to Change the Modes, check out this Magento 2 Devdocs tutorial.
Above, we have delivered 25 tips for Magento performance optimization. While some of these practices might be a little trickier than others, it does bring satisfactory results to your site, and if you encounter any roadblock while working with your Magento store, don’t hesitate to reach out to us at any time.
BSSCommerce dedicated to your journey, we believe that every customer is not just a project, but a lifetime commitment. We offer a well-rounded performance check and speed-up consultations, and our Magento solution specialists & senior developers will get rid of any hidden issues your site has with speed optimization. We also got you covered with any other service, from web development, maintenance to migration, data entry, etc.
CONTACT NOW to explore our services and boost your business to the next height!