CDN for Magento 2

The ideal scenario for a website built on Magento 2 platform is to use CDN or content delivery network to serve page assets such as JavaScript, CSS, Fonts, HTML and finally Media to a client’s browser.

content delivery network (CDN) is a system of distributed servers (network) that deliver web pages and other Web content to a user based on the geographic locations of the user, the origin of the webpage and a content delivery server.

This service is effective in speeding the delivery of content of websites with high traffic and websites that have global reach. The closer the CDN server is to the user geographically, the faster the content will be delivered to the user. CDNs also provide protection from large surges in traffic.

For Magento 2 website to be able to serve media (image files including Product Images, CMS WYSIWYG stored under magento/pub/media/ directory) from a CDN server few changes should be done. As per my experience setting up CDN server, there is a minimum set of actions should be done.

.htaccess file Update the magento/pub/media/.htaccess file and set additional Header for allowing CORS processes images. There are a good few scenarios in Magento 2 where images are requested via XMLHttpRequest.

Apache Header Module Enable additional Header module for Apache server. This will allow to read and process additional CORSheader set in the .htaccess file.

CNAME Additional CNAME or domain name might be created, something like cdn.mywebsite.com to have a custom domain for all your media assets stored under CDN.

At most important is to configure actual CDN server. Here you may select server depending on your expectations and resources available.

The question of the Week

What do you want to see more or less in this weekly newsletter? Is there anything you would like to share or provide feedback?

This would mean a lot to me to hear your thoughts.

Send your replies to blog@maxpronko.com


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *