Azure: MVC application to refer js from blob

Azure: MVC application to refer js from blob

When deploying your MVC application package to Microsoft Azure, all the script files are deployed to Azure within the package itself. You can give direct reference to js files within your views or you can bundle those files and then give the reference to the
bundle(s). More information about bundling is available here.

Once you have such an application deployed live into Azure then users will expect you to quickly fix any error they see.

If a fix involves code change (that means C# change) then you need to redeploy the package after your fix. This will reset your application and can mean downtime.
If a fix involves only js code change then we can avoid Azure deployment and just fix the bug in the js file and upload to the Azure blob. will solve your problem with zero downtime. More information about Azure storage, you can be found here.

So, here I am pointing to the following architectural implementations:

You need to deploy your application to Microsoft Azure having your web and worker roles

Keep all the js files into the Azure blob

In your view files give the reference of js files in the following manner:

If(application runs in debug mode)

Refer local js files

Else

Refer js from the blob

After reading this much information about this post you might be thinking about CDN. But the extra feature/thing you can achieve with the given approach is, you can keep your
blob as a private one. While CDN is a public one which is accessible to all.

Now, to automate the process of uploading the js files from your local machine to blob I have a simple solution for you. Here is the PowerShell that will help you to upload the js files from your
local hard drive to Azure blob container.

NOTE: Here I am assuming that you have blob container having the name as "scripts".

Param(

$StorageContainer = "scripts"

)

# The script has been tested on PowerShell 3.0

Set-StrictMode -Version 3

# Following modifies the Write-Verbose behavior to turn the messages on globally for this session