How to Set Up a Content Delivery Network (CDN) in Magento 2?

How to Set Up a Content Delivery Network (CDN) in Magento 2?

As the title indicates, this article will discuss everything there is to know about setting up a content delivery network (CDN) in Magento 2. However, we first need to familiarise ourselves with a CDN.

What is a Content Delivery Network?

The simplest way to define a CDN is that it is a group of servers that are dispersed across different geographic locations. These servers are used to cache content close to users. Today, every major website or web application uses a CDN to serve its users. The below image provides a visual explanation of how a CDN works.


Source: Cloudfare

As can be seen in the above image, the content is delivered to the user from the closest server rather than the origin server. This ensures minimal load on the original server as the traffic is distributed across various servers. Nowadays, the use of CDN has become quite important. The most notable example is Netflix.

Did you ever wonder how users are able to watch their favourite content in high-quality without worrying about downtime or service degradation? Considering that Netflix has millions of subscribers, this is no less than an achievement. It is made possible only through the efficient use of CDN.

The below image shows the extent to which Netflix relies upon CDNs.


Source: Netflix

Given Netflix’s growing subscriber base, it is likely that Netflix will set up more servers in the coming years. Now, before we elaborate on the steps to set up a CDN in Magento, we’ll talk about why using a Magento CDN is a must nowadays. This will give a better understanding of CDNs.

Benefits of a Magento CDN

Improves Loading Speed

Nowadays, website loading speed has a direct impact on the user experience. If a website or web app takes longer than 3 seconds to load, users will simply move on. Most recent statistics point that the waiting time has come from 3 to 2 seconds. Naturally, as internet speeds improve, users will expect faster loading times.

A CDN increases a website’s loading speed by delivering content to users from the nearest servers. Thus, if a user in Australia logs into Netflix, they won’t be accessing content from a US server. Instead, they’ll be linked to an Australian server. This localisation of content ensures minimal loading times.


During promotional events, websites experience high levels of traffic. Suppose you are running a Magento store in the UK. During the Christmas period, you decide to slash product prices by up to 50%. Naturally, this will drive traffic as the audience will be looking to get a good deal.

In most cases, when websites experience a sudden increase in traffic, the server goes down. It means the website won’t load for most users. Even it does manage to load, the speed will be quite slow, thereby leading to negative user experience. This is where a CDN comes into play.

It helps distribute traffic across multiple servers, thereby helping online stores deal with sudden increase in traffic. By keeping the store operational during sales events, you can generate considerable sales. At the time, users will be extremely happy and reward you with positive word of mouth.

Increases Ranking

Google and almost every other search engine uses a website’s loading speed in their search algorithm. Thus, higher the loading speed, the better the ranking in search engine result pages. As CDNs boost a website’s loading times, Magento store owner can expect a noticeable increase in rankings.

In other words, a CDN can boost your search engine optimisation strategy. However, SEO is a vast field. Using a CDN alone will not do much to improve rankings. You’ll have to come up with a comprehensive strategy which focuses on off-page, on-page, and technical SEO.

You also may want to read: Top 8 CDN Providers for Magento 2

Now, let’s turn our attention to how to set up a CDN in Magento.

A Step-By-Step Dive into Setting Up a CDN in Magento 2

Step 1: Log in to your Magento 2 admin panel and navigate to Stores SettingsConfiguration.

Step 2: In the left panel under General, choose Web.

Step 3: In the upper-left corner, set Store View as needed

Step 4:Expand Base URLs section and do the following:

  • In the Base URL for Static View Files field, enter the CDN URL for static view files.
  • In the Base URL for User Media Files field, enter the CDN URL for JavaScript and CSS files.
Step 5: Expand Base URLs (Secure) section and do the following:
  • In the Secure Base URL for Static View Files field, enter the CDN URL for static view files over HTTPS.
  • In the Secure Base URL for User Media Files field, enter the CDN URL for JavaScript and CSS files over HTTPS.

Step 6: Click Save Config.

Step 7: Flush the Magento 2 cache by going to the main menu, selecting System Cache Management. Click Flush Magento Cache. After flushing the cache, your Magento 2 store should now be using your CDN.

Additional Tips to Keep in Mind When Using a Magento CDN

  • If you are using a CDN with a custom domain, you will need to create a CNAME record for your CDN domain that points to your Magento 2 store's domain.
  • You can test your CDN configuration by using a tool like Pingdom or WebPageTest.
  • If you are having trouble setting up your CDN, you can contact your CDN provider for support.

Who Should Use a Magento CDN?

From an eCommerce perspective, the following Magento stores must use a CDN:

Large Stores

Magento stores with a large product catalogue must invest in a CDN. Since the website is filled with high-resolution product images and other media, loading times can be slow. A CDN can boost the website loading times.

Geographically Dispersed Stores

If a store is active in multiple regions, investing in a CDN is a wise choice. The CDN will serve users through a server closest to them.

High Traffic eCommerce Stores

As mentioned earlier, CDN is a perfect solution to deal with sudden increases in website traffic. If your website already enjoys a good traffic, investing in a CDN can help offset the impact of any sudden increase.

Final Thoughts on Magento 2 CDN

This concludes our article on setting up a CDN in Magento 2. As you can see, the steps are quite straightforward. Nevertheless, if you still face any issues, contact our support team. They’ll guide you through every step.