How to make Magento 2 faster by integrating CloudFlare

Tips and Guides/ 02nd Nov 2017/Will Cook-Martin

Magento Guides

Integrating a Content Delivery Network (CDN) with Magento 2 is one of the simplest ways to make your Magento store faster.

The end result is that your static content i.e. images, JavaScript and CSS, will be delivered from a server closest to your shoppers. This can result in a faster Magento store and as an added bonus, a reduction in load on your server and lower bandwidth usage.

The following guide will detail how to make Magento 2 faster by integrating CloudFlare. This guide includes the use of cPanel, though you can perform this just as easily using an alternative admin panel or even via the command line

Did you know…

At Clook, one of our specialisms is providing Magento optimised hosting which is significantly faster than a standard install. If you’d like to find out more please get in touch with us.

1
Create a CloudFlare account

If you don’t have a CloudFlare account, create one and add a domain using this tutorial.

2
Create a subdomain

Using cPanel, create a subdomain for your CDN content and point it to your Magento install directory. Here my install is in public_html/magento.

You can call the subdomain anything you like but we recommend something similar to cdn for ease of recognition.

create_subdomain_cpanel

3
Create a CNAME record in CloudFlare’s DNS settings

Follow this guide to add a CNAME record in your CloudFlare dashboard, though instead of using “blog” use “cdn” or whatever subdomain you created in step 2, as below.

make Magento 2 faster by integrating CloudFlare

4
Review CloudFlare’s DNS settings

Check that the only record that has its traffic routed through CloudFlare’s servers is the one you created in step 3.

In the image below you can see that only the CNAME record cdn is passing through CloudFlare’s network, as indicated by the orange cloud.

If there are any other records that are passing through CloudFlare’s network, i.e. those that have an orange cloud, click on them and ensure they are grey and therefore no longer being passed through CloudFlare’s network.

cloudflare_dns

5

Login to your Magento admin and navigate to Stores > Configuration

Magento 2 config

6

Click on the Web link under the General tab in the left hand menu.

Magento 2 General settings

7

Edit Base URL for Static View File, and Base URL for User Media Files under the “Unsecure” tab so that it references the CDN subdomain path that you created in step 2.

i.e. enter as below but swap cdn.yourdomain.com for the subdomain you created in step 2

If your site also uses https, be sure to duplicate under the “Secure” tab

Magento 2 CDN settings

8

Clear your Magento store’s cache – System > Cache Management > Flush Magento Cache

Your Magento 2 store’s static content should now be being served by CloudFlare. You should notice a reduction in load and bandwidth usage on your server and hopefully a performance improvement.

Will's our technical sales guy from the hills of Rossendale. A follower of Stoke City, father to Eddie, husband to Catherine and a fan of gadgets - oh and he's recently mastered the art of really slow DIY.
We have a very strong team here at Clook and we build on everyone's strengths and weaknesses, you have to be able to make a good brew too!

Chris James

Customer Login

Forgot Password? Cancel