At Hostdedi, we spend a considerable amount of time optimizing our infrastructure to make your Magento 2 store faster. After years of research and development, we’ve pulled together the ultimate Magento 2 performance checklist:
- Remove unused modules: Magento 2 comes with many pre installed modules that aren’t always needed. Yireo created a great module to disable the optional modules you don’t need through composer. The idea behind the module is quite simple: you replace any unused module with nothing to avoid loading unused modules and classes. This module and a complete how-to can be found here: https://github.com/yireo/magento2-replace-tools
- Enable CSS/JS minification and merging: Minifying and merging CSS files can greatly improve load times and the general performance of your store by cutting the number of requests your site makes when loading a page. You can minify and merge CSS and JS files from the admin panel by navigating to the Developer tab under Stores > Configuration > Advanced (keep in mind this tab will only show if you are using developer mode). Magento recommends using a 3rd party plugin like Baler or MagePack for JS bundling given that Magento’s bundling mechanisms are not optimal and should only be used as fallback alternatives.
- Enable production mode: While this one might seem simple, the number of sites we see using a different mode in Magento is staggering. No one should be running Magento 2 in production in a different mode, but we still see too many stores running on either default or developer mode. The best way to switch modes is via CLI:
to see which mode is your store using and
php bin/magento deploy:mode:set production
to set production mode
- Use Redis for session/default and full page cache: Redis is one of the most used key/value database engines and Magento 2 comes with integrated support to use it as a both session storage and default/full page. To configure your store to use Redis, run the following commands from your root folder:
bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-<parameter_name>=<parameter_value>...
bin/magento setup:config:set --session-save=redis --session-save-redis-<parameter_name>=<parameter_value>...
- Use Elasticsearch for Magento’s catalog search: Since Magento 2.4, MySql was deprecated (and removed) and Elasticsearch was introduced as the catalog search engine, greatly improving the speed and results of the searches. To enable Elasticsearch, navigate to your admin panel and under Stores > Settings > Configuration > Catalog > Catalog > Catalog Search you will find a tab called Search Engine. Configure your store to use your Elasticsearch endpoint, click Test connection and if everything worked, you’re all set. You can find the complete list of parameters to configure Elasticsearch here.
- Use Varnish to speed up your response time/TTFB: You either love or hate Varnish but at the end of the day, it greatly improves the TTFB, and if configured correctly, it can do wonders for the general usability and user experience of your site. Magento 2 features an out of the box integration, making Varnish configuration really simple. To configure Varnish, navigate to Stores > Settings > Configuration > Advanced > System > Full Page Cache, select Varnish from the Caching Application list and configure the rest of the options. A full list of all the parameters you can use to configure Varnish can be found here.
You can also configure Varnish from the CLI by running:
php bin/magento config:set --scope=default --scope-code=0 system/full_page_cache/caching_application 2
- Enabling the Asynchronous email notifications, Asynchronous order data processing: during times of high concurrency, you might want to move processes that handle checkout, order processing email notifications and stock updates to the background. To enable async email notifications, go to Stores > Settings > Configuration > Sales > Sales Emails > General Settings > Asynchronous Sending
You can activate Asynchronous order data processing from Stores > Settings > Configuration > Advanced > Developer > Grid Settings > Asynchronous indexing
When enabled, orders will be placed in temporary storage and moved in batch to the Order grid without any collisions.
While there are no real magic tricks, we tried this guide in our cloudhosts and ended up with an A and a page load under 2 seconds on GTMetrix 🥳