I\'m trying to render a JavaScript bundle using Microsoft\'s Web Optimization framework, like this:
@Scripts.Render(\"~/assets/bundle.js\")
One easy way is with Scripts.RenderFormat:
@Scripts.RenderFormat("<script src='http://my.site.com{0}'></script>","~/assets/bundle.js")
A way to get URL from request. Couldn't seem to use multiple parameters with the RenderFormat, so that's why it looks a little ugly:
@Scripts.RenderFormat("<script src='//" + @Request.Url.Host + "/{0}'></script>", "~/assets/bundle.js")
or better yet, centralize a function to get the correct path (using a fictional function):
@Scripts.RenderFormat("<script src='" + @Tools.GetRootURL() + "{0}'></script>", "~/assets/bundle.js")
Also, you don't need the .js
on the bundle:
bundles.Add(new ScriptBundle("~/assets/bundle")