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

JavaScript Functions

  Hi there, and welcome to another exciting lesson on JavaScript. If this is your first time here, please do well to check out our previous lessons. In the previous lesson, we were discussing JavaScript math methods. It was very intuitive as we got to learn how to use the various math methods. To proceed, we shall be looking at JavaScript functions.  A function in JavaScript like in every other programming language could be defined as a block of code that is written to perform a particular task, and this function is usually invoked or called before it is being implemented. We have been talking about methods throughout the previous lessons right. Do you know that those methods are actually functions? Yes they are functions. You can now have an overview of the importance of functions in every programming language. How do we create a function in JS? To create a function, you follow the format function functionName(Argument) {//Block of code }. Some functions do have a return val...

JavaScript Math Methods

Hello everyone, and welcome to another exciting JavaScript lesson. In the last lessons you have been seeing other methods being used in JS (for example, the string methods). We shall go further into exploring other methods. This time, it’s going to be math methods. Do not move an inch because it’s going to be a very exciting. Before we look at what a math method is, let’s have an overview of math objects. A math object in JavaScript is a static built-in object that includes properties and methods used in performing mathematical tasks. Talking about math properties, they have the syntax Math.property . Some examples are Math.E that returns Euler’s number, Math.PI that returns PI, Math.LN2 that returns the natural logarithm of 2, and many others. The various JavaScript methods contained in the math object, thus, make mathematical operations easier and reduce effort as well as time in math-oriented programming. Some JS methods include abs( ), ceil( ), cos( ), sqrt( ), pow( ), log( ) ...

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...