Skip to main content

Magento 2 Slow? Speed Up Magento 2 (2021)

We are learning the basic Magento 2 performance setup in our last blog. also, We have checked how we can test our website using google page speed and GT Metrix. If you are not aware of it, then click here 👉 Magento 2 Performance Optimization

Magento 2 system Requirement

 It’s very important to choose the best server. If the particular server you picked is not functioning smoothly, you won't have good website speed. Before starting performance optimization in Magento 2, We suggest you use the best server.

Always use the dedicated server or VPS, do not pick a shared hosting option.

Check the Magento 2 system requirement before you purchase the server.

  • Memory requirement: Memory should be 2 GB RAM or higher.
  • Database: Use always the latest MySQL version.
  • PHP: Use the always updated PHP version.
  • Magento  Version: Use the always latest Magento version.
  • SSL: A valid security certificate is required for HTTPS. Self-signed SSL certificates are not supported. 
  • Mail server: Mail Transfer Agent (MTA) or an SMTP server
Note : If you want to check more about system requirement guidelines, then go to the magento official website. Click Here 👉Magento system requirements

CDN (Content Delivery Network)

It's used to reduce a load of your server by serving some of the website’s content. So, It brings high performance by delivering your content quickly.
AWS (Amazon CloudFront) Server :
Amazon CloudFront is a highly secure Content Delivery Network (CDN) that provides both levers (network and application) protection. 
Magento can utilize the following technologies :
  1. Varnish Cache
  2. Redis Page cache
Magento Full-page Cache
When a customer is accessing your website, a request is made to the server.  At a time returning the corresponding HTML to be displayed to the user. Full-page cache stores that HTML response, so that the next request will directly return it, skipping all the back-end processing and database queries. So, using the full-page cache makes the website much faster.

We can enable the full page cache using the below command:
php bin/magento cache:enable full_page

How to use Varnish for Full-page Cache
After, Enabled the full page cache, Use Varnish to handle it, not files. Magento strongly recommends using Varnish OR  Redis in production mode.

The varnish is designed to accelerate HTTP traffic. How to set up the varnish cache, Magento provides it on the official website. click here ðŸ‘‰Install Varnish

Let's configure the Varnish cache.


  1. Log in to the Magento Admin Panel.

  2. Go to the Stores > Configuration > Advanced > System > Full Page Cache

  3. Now, Open the “Caching Application” and select the “Varnish Cache (Recommended)”

  4. Enter the TTL for public content.

  5. You can check the Varnish Configuration as per the below screenshot and enter the given information about the Varnish configuration.

Magento 2 Slow? Speed Up Magento 2 (2021)


Some tips for improving in coding Full-page Cache Works.

1)Don’t use the attribute cacheable="false" in the layout XML block.

2)Always use production mode in live websites.

3) test whether or not your page is cached manually. You can put the store on developer mode and run the cache clean command. Inspect element and check the Network tab. Refresh the page.

GZIP Compression

Gzip is a method of compressing files for faster network transfers. You can check in GTmetrix regarding the GZip.

How Can we enable it?

For Apache servers
Copy and paste the following code into your .htaccess file:

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

Use Elasticsearch on Search and Catalog Pages
 Using Elasticsearch you can increase your website speed. First, you need to set up your Elasticsearch server and connect your Magento website. Using ElasticSearch, Searching becomes much faster.

Visit the Magento 2 official website for how you can 👉 configure Magento with Elasticsearch

Let's Configure,

1. Open the Admin Panel.
2. Go to the Stores > Settings > Configuration > Catalog > Catalog > Catalog Search.
3. From the Search Engine list, click Elasticsearch or Elasticsearch 6.0+ 
Magento 2 Slow? Speed Up Magento 2 (2021)
Remove the Unnecessary Ajax Calls
Ajax call takes more time to load the page. So, use only necessary Ajax Calls and remove the unuseful ajax call.
Go to the Network tab and there you can filter the request by XHR. you can see all the Ajax requests of the page and check them to see which of them are useful on that particular page.
Set the Indexers to “Update on Schedule”
Magento 2 indexers provide the  below two modes
1)Update on Save 
2)Update on Schedule

If set to “Update on Save” every time you save a product, category, or Attribute, the specific index starts running. that's why your server becomes down.

So, set the "Update on Schedule" indexer, Indexer are executed by the cron job at a specific time that you set. 

Comments

Popular posts from this blog

Introduction to flask

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session because we are entering into one of python’s web-based application called flask. In this article, we are going to see the following What is flask Prequistes Installation of flask in python Some of flask template engine. What is flask? Flask is one of python-based framework which is used to create web applications. Flight is a very light web framework. During installation, flask comes with pre-installed modules and functions which are used to backup your own web applications. Flask is very easy to understand and perfect go-to for beginners and with flask, a web server can run in less than 3 lines of code. Prequistes Before learning flask, we recommend the reader to have a basic mastery of python concepts. Installation of flask  Before installing flask, we have to checked if python has been installed or. If n...

How to generate random numbers using NumP1

Hello. Welcome to another edition on this platform. For more better understanding, do checkout our YouTube channel to get the video tutorial. In this article of today, we are going to see how to generate random numbers using any of the following methods: Generating a random number Generating a random float and integer Generating random number arrays Generating random number from an array What is a random number? This is a number which cannot be predicted before its occurrence. This number might not different every time. Programmatically, they are two categories of random numbers:     Pseudo-Random numbers       True Random numbers. Just as programs which are written by programmers are a set of instructions, we must follow an algorithm to generate random numbers. Random numbers which are generated using an algorithm are called Pseudo-Random numbers. To generate a true random number, it is important to get the data from sources such as the keyboards, mou...

Introduction to Django

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session. we are entering into one of python’s application called Django. In this article, we are going to discuss the following: What is Django Why must we use Django  A brief history of Django Installation of Django Popularity of Django What is Django? Python has so many framework application and Django happen to be one of them. Being a python-based-framework, it is used to quickly create web applications.  When building websites, django provides similar ready-made components to handle user authentication, forms, a way to upload components. Why use django? Django is very fast. It takes applications from concept to applications very quickly Django has thousand available packages in it when it is installed. With django, we can launch web applications is a matter of hours. Django is a highly is secured and helps...