In MVC4's Web.Optimization bundling / minimization, is it possible to register a bundle on one site (our static cookieless domain) and then use that bundle on another site (our webapp domain)?
eg static.myapp.com has a BundleConfig.cs with
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/Scripts/static")
.Include("~/Scripts/*.js"));
}
Can that bundle be used in a view on the webapp's domain, eg www.myapp.com has this in Site.Master
<%= Scripts.Render("static.myapp.com/Scripts/static") %>
Can this be done with MVC4 bundling? Serving static files from a cookieless static domain is a well known performance improvement.
Bundling in ASP.net MVC allows you to optimize the deployment of scripts and stylesheets by replacing the placeholder
Scripts.Render()
at Runtime rather than at Design time. When the page is parsed and pushed to the client, the bundles registered to the calling server are parsed into the output buffer. Therefore the app serving the content must be running the bundler service. If a web app not running bundling encountered theScripts.Render()
element, it would either outputnull
or throw an exception.you can, however, use CDN references in your RegisterBundles method, like:
In the code above, jQuery will be requested from the CDN while in release mode and the debug version of jQuery will be fetched locally in debug mode. When using a CDN, you should have a fallback mechanism in case the CDN request fails.
Edit
You could use ASP.Net MVC to serve as a CDN from static.myapp.com something like