Is Remote Bundling of resources on a CDN possible?

332 Views Asked by At

I'm trying to move all my javascript and css (less files etc) to a separate site which will be hosted on a site that we will use as a CDN.

However I want to make use of MVC ScriptBundle and StyleBundle classes to tie into BundleTransformer.Less.

At first I just tried a test script bundle like so:

Bundle mainScript = new ScriptBundle("~/bundles/scripts/test.js", @CDNUrl + "lib/jquery/2.1.4/jquery-2.1.4.js");
bundles.Add(mainScript);

The issue here, is that if I am in debug mode or optimizations are off, no script is output because I didn't include anything. And if I turn optimizations on it just drops the cdn link in a script tag.

Ideally I don't want to have to include the scripts and styles in the site (I could map a virtual directory to where they are on the cdn).

What I want to do is build all my bundles on the CDN, and just link to them via

<script src="//cdn.etc.com/bunles/xyzSiteScripts.js"></script>

However a minimized link get's generated like so:

<script src="/bundles/scripts/test2.js?v=SQINHU6JqPGF50s4ugWSC_sMpTAqiQhXWc8eDYzbyDg1"></script>

v on the query string is the cache buster. I am considered that if I just link to them I will have to manually update all my links with new cache busters every time I chance one.

Is there a way to handle this already that I am missing? From what I gather, if I move the bundling to the CDN itself, then I won't be able to use @Scripts or @Styles in my razor templates.

0

There are 0 best solutions below