Hosting a CDN Endpoint in Azure

by Michael Szul on

No ads, no tracking, and no data collection. Enjoy this article? Buy us a ☕.

Content delivery networks (CDN's) have become increasingly popular for hosting JavaScript libraries for others to link too quickly without having to download files locally. It benefits the user by giving them a stable external link to a library, and it benefits the developer by offering a lower barrier to entry for those wishing to try out the developer's library.

It probably surprises nobody that Microsoft Azure allows for creating CDN endpoints, which gives developers the ability to essentially host their own CDN with their own Azure account.

The first thing you need is either a storage account or web application account, for my Metron library, I went with a storage account in order to keep the library disconnected from any one domain. In addition, storage accounts are far cheaper than web application accounts. For locally redundant storage (LRS), Microsoft charges $0.024 per GB per month for the first terabyte of storage space for standard blob blocks (as of June 4th, 2015).

Azure makes it easy to create an LRS storage account:

Once you have the storage account, it's a good idea to create a container that you can use as a folder representation of storing your files.

Once you have the container created, you can create a new CDN. Using the "Quick Create" option in the menu, choose your subscription, set the origin type to "storage accounts," and select the storage URL for the origin URL.

One caveat of Azure blob storage is that there is no immediate interface for uploading files. Azure tools for importing data are meant for large scale data jobs (hard drive importation), while typical access is done programmatically through code. One option is to use the Azure Storage Explorer, which requires a storage account access key found on the dashboard view of your Azure storage account.

With your files uploaded, you simply need to append your container and file name to the CDN endpoint URL, and you're all set. For example, my endpoint is http://az765165.vo.msecnd.net, my container is "Metron," and my file is metron-0.4.3.js, so the CDN URL ends up being http://az765165.vo.msecnd.net/metron/metron-0.4.3.js.

Now you can allow Azure to handle CDN hosting for all your libraries.