Independence Day Offer. Save 25% on Magento Hosting. Sign Up Now.

How to Set Up CDN in Magento 2?

Magento is a popular Ecommerce platform used by big brands and large traffic websites. 

Ecommerce stores have lots of images, variations of products, and different sizes. To load the Ecommerce website at fast speed, Magento stores owners use CDN – Content Delivery Network.

Let’s seewhat is CDN and how to set up CDN in Magento 2.

In this article, you will learn:

What is CDN?

Content Delivery Network (CDN) is a network of servers and data centres distributed across the globe to provide higher application availability. These data centres act as middlemen between the original server and the browser sending the request. 

CDN uses points of presence (PoPs) to make a cached copy of the content and serve it to the user the next time the request is made. The PoP is near the user compared to the original data centres; hence, the content is served from a shorter distance, reducing latency.

The caching ensures that the store is available even if the original servers are down or unable to serve the request on time, which improves the availability of the store.

Importance of CDN

Traditionally, the content is stored at one location – a central server.

But the CDN enables the website owners to distribute the content copies to multiple servers at different locations. When the browser makes a request, it does not have to travel to the central servers; instead, the server geographically closer to the user responds with requested data. 

Any web assets required to load the webpage, including HTML code, Javascript files, stylesheets, images, videos, and CSS, can be channelled through CDN. Today, every high-traffic website like Facebook, Netflix, and Amazon uses the CDN to accelerate the data.

The biggest benefit of using CDNs are:

  • Faster website loading
  • Reducing bandwidth costs
  • Content availability
  • Website security

Let’s see how CDN helps Magento 2 store.

Advantages of using CDN for Magento 2

#1 Faster website loading

What is Network Latency?

Network Latency is the time it takes for a file to travel between source and destination. In this case, it is the time taken by request/response to transfer between the web server and browser.

The network latency depends on the hardware used and the distance between two points. The more the distance between server and browser, the more latency.

It is measured in milliseconds but can increase the website time if the distance is considerable. 

For example,

Case Q: The site’s data is in America, and someone from America opens the page. The data has to travel from America to America.

Case W: The site’s data is in America, and someone from England opens the page. The data has to travel from America to England.

Which case do you think has more latency?

CDN solves this. CDN hosts cached website content at one of the PoPs in England. Hence reducing the distance by a lot. Reducing the network latency and improving the website speed.

#2 Reducing bandwidth costs

Every time the server responds to the request, it costs you the bandwidth. However, the bandwidth is not expensive if it’s a small store.

But it becomes one of the deciding factors for big sites with millions of page views. AWS Cloud, Google Cloud, and Azure cloud all charge for the bandwidth, and if the application gets sudden traffic, it can increase the bill by thousands of dollars.

With CDN, the server does not get a hit until necessary. The CDN served the requested data. No hit means no bandwidth consumption and low bill.

#3 Content availability

Hardware failure or unexpected increase in traffic due to promotional events (as happened with Coinbase during Super Bowl Ad) or a bot attack can lead to web server downtime.

The users may not be able to open the webpage, and your business can suffer a cost.

CDN comes with features that can minimize downtime. First, the cache could be served instead of the website for the static content. Secondly, the CDN load balances the traffic to several servers, reducing the impact on anyone server and eventually managing the scaling of traffic.

#4 Website security

All the CDN comes with security tools that can be activated on the website. The SSL certificates, DDoS mitigation, data encryption, and minification.

IP blocking and bot protection are also a part of the CDNs. But you have to select the CDN that offers the security features.

So besides fast, CDN also keeps your Magento store safe.

How does CDN Work?

CDN works with the PoPs – the building blocks of the network. Also known as edge servers, they are data centres responsible for setting up communication channels with the user under their geographical range.

The CDN works:

Content Provider: The website/app that is providing the content. Let’s say Amazon.

Authorization: The content provider authorizes the CDN to serve the content on behalf of the Content provider. It is done by setting the Domain Name Servers.

Reporting: CDN provides the data, and statistics related to the application performance, visits, views, and user session to the content provider.

Source: Source of the content. A copy of the content is made to the CDN to serve the user.

Content: The content that can be sent to the user.

Request: A request is made to the server when a user opens an URL. The request contains the data information required to open that webpage associated with the URL. The CDN in the middle intercepts the request and check if the cached copy is available.

Deliver: The CDN reads the request, and if the cache copy is available, it sends the response. If it is not available, it passes the request to the server.

User: The user clicks on the URL or opens a webpage.

Configure CDN in Magento 2

Step 1: Log in to your Admin Panel

Step 2: Navigate the Stores > Settings > Configuration

Step 3: On the left panel, click on the Web under the General tab.

Step 4: Configure the two sections: Base URLs and Base URLs (Secure)

Step 5: Configure the Base URLs. Expand it.

  • Base URL for Static View Files: Enter the URL of the location where the CDN has stored the static view files.
  • Base URL for User Media Files: Enter the URL of the JavaScript files on the CDN.

Step 6: Configure the Base URLs (Secure). Expand it.

The same steps have to be taken here:

Base URL for Static View Files: Enter the URL of the location where the CDN has stored the static view files.

Base URL for User Media Files: Enter the URL of the JavaScript files on the CDN.

Step 7: Click on the Save Configuration button to save the changes.

Configure CDN in Magento 2 in Breeze

At Breeze, we understand the importance of CDN for Magento store owners. Hence we integrated Cloudflare (most popular and best CDN in the market) within the product.

Find the DNS option on the left side of the dashboard. Please follow the steps to set up Cloudflare for Domain management.

Hosted with Breeze, your store will have CloudFlare CDN and the benefits that come with it.

Final Words

A CDN can enhance your Magento store’s availability, reliability, and speed if you are selling globally.

CDN ensures Ecommerce store:

  • Load quickly for the user
  • The server does not overload
  • Traffic is distributed to multiple servers through load balancing
  • Have minimal downtime in case of outrage
  • Have SSL certificates
  • Is protected the store from Bot and DDoS Attack

This article shows you how to use the CDN with Magento 2. Breeze makes it much easier. 

If you encounter any problem, leave it in the comment box, and one of the engineers will help you out.

Latest Magento Tips, Guides, & News

Stay updated with new stuff in the Magento ecosystem including exclusive deals, how-to articles, new plugins, and more. 100% Magento Goodness, a promise!

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top

Talk to a sales representative

USA / Worldwide




We can help you. Right now.

Fast growing merchants depend Breeze for high-performance hosting. Experience counts. Let's get started.

Request demo

Please fill in the details below and we’ll reach out to you with a customized demo of our product!

Get your FREE Image SEO Checklist

Bring more visitors to your image from Google search from the existing images.