Search code examples
visual-studioazure-cdn

How to publish static files to Azure CDN without scripting


I found an old article that explained how to put static files inside my Visual Studio project /cdn folder and they would be uploaded to Azure CDN.

After searching the web for something more recent the only solutions i found involved config files and powershell scripting.

I am looking for a Visual Studio plugin/addon or nuget package or even a feature in VS I am unaware of that can allow me to keep my /Content folder of static files on Azure CDN using the GUI / Wizard that will reroute those css/js/img references to the cdn automatically.

Seems like this would already exist but I havent been able to find it.


Solution

  • You can't really "upload" files to Azure CDN. Azure CDN is not a storage host like Azure Blob Storage or S3.

    The basic structure is that you use your web server as an origin(where CDN load files from) and then instead of using the origin url in your website for static files, you use the CDN url so that when user open a website, the file is loaded from CDN instead of the origin.

    Let's say your CDN and your website is already setup on Azure. What you would need here is an automatic tool to replace all the relative url (pic/mypic.jpg for example) to a CDN url (myendpoint.azureedge.net/pic/mypic.jpg). However, I don't think there is a tool for this. Also even this tool exist, this will break the "best practice". Because what you really want is to add a class on all of your url tags and then using javascript to update the url tag in the class and by defining the CDN endpoint url in a better place, you can avoid copy past url everywhere. In this way, you can control using CDN or not easily, you can also control using which CDN easily