Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.net MVC static resource bundles and Scripts.Render()
    primarykey
    data
    text
    <p>I'm trying to implement some static resource improvements into my ASP.net MVC 4 project (VB.net) by changing how static resources such as javascript and css files are retrieved.</p> <p>I've been following this link (<a href="http://www.dotnetexpertguide.com/2012/10/aspnet-mvc-4-cookieless-domain-for-bundling-and-static-resources.html" rel="nofollow">ASP.NET &amp; MVC 4: Cookieless domain for bundling and static resources </a>) to help accomplish this but I've come across an issue whereby unbundled javascript and css files are not rendered.</p> <p>Normally when rendering .js or .css bundles you use the following:</p> <pre><code>@Scripts.Render("~/bundles/jquery") </code></pre> <p>This will then render each script tag separately in the ~/bundles/jquery bundle when in development mode, and render a single script tag pointing to the minified bundle when in production.</p> <p>According to the link above, when the scripts are bundled into a single file, you can use the following line:</p> <pre><code>&lt;script src="@Url.StaticContent("~/bundles/jquery")" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>This works fine for me for bundled files since the src property is valid and the StaticContent function is able to change the src URL. But when in development mode, the bundled file does not exist as no bundling takes place and all scripts are rendered seperately to the browser by <strong>@Scripts.Render</strong> and so this method does not work.</p> <p>Does anyone know if it is possible to create an extension method for the Scripts helper that will accomplish what I need, or am I going to have to do something like this?</p> <pre><code>@If Misc.IsLocalDev Then @Scripts.Render("~/bundles/jquery") Else @&lt;script src="@Url.StaticContent("~/bundles/jquery")" type="text/javascript"&gt;&lt;/script&gt; End If </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload