I have two VS projects, one for the main website and one for a "static content" website where all the css, js, images, and other static content will be stored and accessed via a cookieless domain.
So I have a BundleConfig.cs in my static site that creates all the bundles:
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/bundles/styles").IncludeDirectory("~/app/styles", "*.css", true));
bundles.Add(new ScriptBundle("~/bundles/scripts").IncludeDirectory("~/app/src", "*.js", true));
}
}
And in the main site I have another BundleConfig.cs where I point the main site to the static content site like this:
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
var staticWebsite = ConfigurationManager.AppSettings["StaticWebsite"];
var versionNumber = ConfigurationManager.AppSettings["VersionNumber"];
Styles.DefaultTagFormat = string.Format("<link href='{0}{{0}}?v={1}' rel='stylesheet'/>", staticWebsite, versionNumber);
Scripts.DefaultTagFormat = string.Format("<script src='{0}{{0}}?v={1}'></script>", staticWebsite, versionNumber);
}
}
Now I can use @Styles.Render("~/bundles/styles")
and @Scripts.Render("~/bundles/scripts")
which render like this, just the way I want and it works great:
<link href='http://mycookielessdomain.com/bundles/styles?v=1.0.0.0' rel='stylesheet'/>
<script src='http://mycookielessdomain.com/bundles/scripts?v=1.0.0.0'></script>
The problem I have is that the content is always minified and bundled regardless of whether debug=true
or not. Even if I use BundleTable.EnableOptimization = false
in both BundleConfig.cs files, @Styles.Render()
and @Scripts.Render()
still only render one tag each and refer to content that is minified.
I understand that the main site would have no knowledge of the individual files that were bundled in the static content site, but my hope is that there is some way to manually specify these paths in the main site BundleConfig so that the Render() methods can list them individually when optimizations are off... if I can ever get them to turn off, that is.
new Bundle()
instead ofnew ScriptBundle()
when in debug mode, but I also wanted to have the files list out individually so I wouldn't have to rebuild the bundle every time I made a JS change. I posted an answer that allowed me to do this. – Athamas