Why use @Scripts.Render("~/bundles/jquery")


How does


differ from just referencing the script from html like this

<script src="~/bundles/jquery.js" type="text/javascript"></script>

Are there any performance gains?

This question is tagged with asp.net-mvc-4 asp.net-optimization

~ Asked on 2012-08-30 08:16:54

The Best Answer is


Bundling is all about compressing several JavaScript or stylesheets files without any formatting (also referred as minified) into a single file for saving bandwith and number of requests to load a page.

As example you could create your own bundle:

bundles.Add(New ScriptBundle("~/bundles/mybundle").Include(

And render it like this:


One more advantage of @Scripts.Render("~/bundles/mybundle") over the native <script src="~/bundles/mybundle" /> is that @Scripts.Render() will respect the web.config debug setting:

    <compilation debug="true|false" />

If debug="true" then it will instead render individual script tags for each source script, without any minification.

For stylesheets you will have to use a StyleBundle and @Styles.Render().

Instead of loading each script or style with a single request (with script or link tags), all files are compressed into a single JavaScript or stylesheet file and loaded together.

~ Answered on 2012-08-30 08:22:02


You can also use:

@Scripts.RenderFormat("<script type=\"text/javascript\" src=\"{0}\"></script>", "~/bundles/mybundle")

To specify the format of your output in a scenario where you need to use Charset, Type, etc.

~ Answered on 2013-10-07 19:12:19

Most Viewed Questions: