Magento 2 Speed Performance Optimization – The Ultimate Guide [updated 2022]
Quickread
- 1. Lesser TTFB( average server response time should be less then 1 seconds ) and Reduced Server Load
- 1.1. Optimize TTFB
- 1.2. Use varnish cache instead of magento default Full page cache.
- 1.3. Enable Flat Catalog in Magento 2: not recommended if Elastic search is in use.
- 1.4. Go With Elasticsearch
- 1.5. Minimum logs to be generated
- 1.6. Make sure cache hit ratio is pretty high
- 1.7. Reduce extension
- 1.8. Clean Database Regularly
- 1.9. Upgrade Magento to 2.4.x
- 1.10. Upgrade PHP to 7.4
- 1.11. Use Redis Cache
- 1.12. Delete unused stores
- 1.13. Indexers should be set on schedule
- 1.14. Remove Unused Attributes
- 1.15. Make sure Attributes Properties are defined to Expectation
- 1.16 Check your site speed without Full page cache and it should be less than 1 seconds
- 1.17 Profile custom/third party modules using Magento profiler
- 1.18 Load balancer
- 2. Payload ( excluding JS payload )
- 2.1. Image Optimization
- 2.2. Go for webP images
- 2.3. Lazy Loading
- 2.4. Enable Browser Caching
- 2.5. Add Picture tag for delivering images based on device resolution
- 2.6. Use Brotli or other compression technique
- 2.7 special focus to be on payload above fold.
- 2.8 lazy load images in Menu
- 3. JS Payload
- 3.1. Go for Advance JS Bundling
- 3.2. Minify JS/CSS
- 3.4. Enable Browser Caching
- 3.5 Use highly optimized theme like Hyva( Recommeded but this will result in a much higher development cost )
- 3.6 Go for Breeze theme developed by Swisslab (Recommeded but comes with challenges as requireJS has been eliminated so any module installed needs to be modified )
- 3.7 custom code your theme to eliminate require.js and Jquery library.
- 3.8 Objective should be to reduce JS payload less then 300 KB
- 4. Server Configuration
- 4.1. Make sure unwanted cron is not getting executed plus schedule cron efficiently
- 4.2. Activate Production Mode to Boost Magento 2 Speed
- 4.3. Enable Gzip Compression or better go for Brotli compression
- 4.4. Use HTTP2
- 4.5. Choose the right hosting
- 4.6. Use Varnish Instead of Full Page Cache
- 4.7. Use CDN to Boost Up Content Delivery
- 4.8. Upgrade to a higher Mysql version
- 4.9 Check with New relic for load.
- 4.10 Go for the upgraded PHP version
- 4.11 Go for an upgrade Mysql version
- 4.12 Use a higher elastic search version
- 4.13 Properly configure Redis
- 4.14 Make sure that IOPs are sufficient
- 4.15 Use litespeed server if this is an option.
- 4.16 CDN to be used to minimize main server load due to processing of js/css/images
- 5. Render Blocking or Total Blocking time
- 5.1. Apply critical css
- 5.2. Move JS from head
- 5.3 eliminate requireJS and jquery( possible by using Hyva or Breeze theme or custom development )
- 5.4 remove JS not required from specific pages.
- 5.5 Use google chrome performance tool to find out JS resulting in render blocking and see if those can be handled.
- 5.6 Replace JS by CSS to reduce JS payload and JS processing time
- 5.7 Replace jquery library with some light weight library or using Java script.
- 5.8 Analyse critical rendering path and see if some preload can be effectively used to reduce the impact of critical render path.
- 5.9 Replace fotorama with a custom photo Gallery as fotorama loads images later
- 5.10 Handle fonts with swap.
- 5.11 Review design specially mobile design and modify elements that are resulting in additional JS( Login popup, carousel, sliders etc)
- 6. Configuration setting that improves performance
- 7. High cache hit ratio :
- 7.1 Use cache warmer
- 7.2 Minimize cache flushing
- Avoid multiple page version by effectively using AJAX/XHR customer data load option.
- Use separate URL version for multilingual as securi and other CDNs might not be able to efficiently handle same code delivery for language change.As then you need to enable header processing and specify some cookie for different language version.
- Define Varnish VCL rules to bypass cache if cache creation will result in too many cache pages( case specific ).
- If pricing has to vary based on customer groups or customer specific then load product price via XHR rather then handle when processing PHP. This will result in same page across all users.
- 8. Image Payload :
- 8.1 Use webP images
- 8.2 Use Picture Tag
- 8.3 Delay loading images that are not visible above fold.
- 8.4 Optmize images
- 8.5 Use browser cache for images.
- 8.6 Use CDN
- Core Web Vitals :
- FID : A proper hosting will take care of this
- LCP : Use preload or modify page design to handle this
- CLS : With proper coding css and html this can be handled
- Following Pages to be considered for optimization
- Home page
- Category/ Product listing page
- Product page ( This is a must if you are into adwords or PPC )
- Cart Page
- Checkout Page.
- Important Blogs
1. TTFB / server load reduction
1.1 Optimize TTFB
1.2 Use varnish cache instead of magneto default Full page cache.
You Might Be Interested In: Magento 2 Speed ( Performance ) Optimization Services
1.3 Activate Varnish Cache
- Go to Stores > Configuration > Advanced > System > Full Page Cache
- From the Caching Application list, click Varnish Caching
- Enter a value in the TTL for public content field
- Expand Varnish Configuration and enter the specific information about your Varnish configuration
1.4 Enable Flat Catalog in Magento 2 ( not recommended if an elastic search is in use )
- Go to “Stores” → “Configuration” → “Catalog.”
- Under “Storefront” change “Use Flat Catalog Category” and “Use Flat Catalog Product” to “Yes.”
- After this, “Save Config” and clear the cache.
1.5 Go With Elasticsearch
- Click Stores > Settings > Configuration > Catalog > Catalog Search.
- From the Search Engine list, click Elasticsearch or Elasticsearch 5.0+ or Elasticsearch 6.0+
1.6 Minimum logs to be generated
1.7 Make sure cache hit ratio is pretty high
1.8 Reduce extension
1.9 Clean Database Regularly
- customer_visitor
- report_event
- report_viewed_product_index
- report_compared_product_index
1.10 Upgrade Magento to 2.4.x
1.11 Upgrade PHP to 7.4 and above
1.12 Delete unused stores
1.13 Indexers should be set on schedule
1.14 Remove Unused Attributes
1.15 Make sure Attributes Properties are defined to Expectation
2. Payload ( excluding JS payload )
2.1. Image Optimization
2.1.1 Serve scaled images
2.1.2 Use of picture tags
2.1.3 Optimize images
2.1.4 Sprite Image
2.2 Go for webP images
2.3 Lazy Loading
2.4 Add Picture tag for delivering images based on device resolution
2.5 Use Brotli or other compression technique
3. JS Payload
3.1 Go for Advance JS Bundling
There is a difference between Magento native SJ bundling and Advance JS Bundling. We recommend advanced JS bundling.There are few modules available to do this bundling.
It bindles JS based on the page where the JS is needed or a general set of JS that’s needed across all pages.
Also, some of the modules have a configuration that allows JS to be moved to a folder or excluded from JS bundling.
If you do not have time to check each JS file and individually handle the configuration for each page then advanced JS bundling is the way.
Amasty has an advance JS bundling module.
3.2 Minify JS
- Go to the Magento backend
- Stores > Configuration > Advanced > Developer > JS Settings
- Set “Yes” for both Merge JS Files and Minify JS Files Options
3.3 Enable Browser Caching
3.4 Objective should be to reduce JS payload less than 300 KB
- Make JS load faster in the browser. Reduce how much JS you use to build your page
- Minify all JS resources
- Use minified third-party JS.
- Only load JS when it’s needed. Eliminate dead JS code. Split JS files to deliver essential components.
- Go for the Advanced bundling
4. Server Configuration
4.1 Make sure unwanted cron is not getting executed plus schedule cron efficiently
Indexing on schedule is what we shall configure.
Not all crons are needed for each Magento website so this should be given thought to.
Also, the default frequency might not be right for all the Magento sites.
Hence a proper evaluation and configuration of corn and indexing need to be done.
4.2 Activate Production Mode to Boost Magento 2 Speed
4.3 Enable Gzip Compression or better go for Brotli compression
4.4 Use HTTP2
4.5 Choose the right hosting
4.6 Use Varnish Instead of Full Page Cache
4.7 Use CDN to Boost Up Content Delivery
- In the Base URL for Static View Files, enter the URL of the location on the CDN where static view files are stored.
- In the Base URL for User Media Files field, enter the URL of the JavaScript files on the CDN
- Open the Base URLs (Secure) section and continue with following:
- In the Secure Base URL for Static View Files field, enter the URL of the location on the CDN where static view files are stored.
- In the Secure Base URL for User Media Files field, enter the URL of the JavaScript files on the CDN.
- When complete, click Save Config.
4.8 Upgrade to a higher Mysql version
4.9 Add Expire Headers
5. Render Blocking
5.1 Apply critical CSS
5.8 Analyse critical rendering path and see if some preload can be effectively used to reduce the impact of critical render path
6. Configuration setting that improves performance
6.1 Full Page Caching: Use Varnish instead of Magento Full page caching.
6.2 Set Indexers to “Update on Schedule”
6.3 Elasticsearch
6.4 Using a Flat Catalog ( If Elastic search not installed )
catalog_product_flat_1 where 1 is the store ID), where each row contains all the necessary data about a product or category.6.5 Content Delivery Network
7. Magento 2 best performance practices
8. Caches
Software Recommendation :
9. APCU is recommended.
Other Points :










