What is the difference between “@Scripts.Render” and “<script>”? [duplicate]

一曲冷凌霜 提交于 2019-12-19 06:35:09

问题


I want to know about the difference between @Scripts.Render("~/something.js") and <script type="text/javascript" src="/something.js"></script>.

Yes, I've already searched about this subject, but with no success. I think if @Scripts.Render exists isn't by chance.

More details

What I'm meaning is: when I should use one or other and why.


回答1:


Scripts.Render is used for bundling, if you bundle multiple scripts together and give them a name, then you can render them all together using this statement.

On debug mode, they'll render multiple tags, and in production you can deploy a single bundled script. Debug mode is set true or false in the web.config:

  <system.web>
    <compilation debug="true" ... />

Here is more about bundling.




回答2:


Functionally, they both have the same result in your example. The Scripts.Render is part of the System.Web.Optimization namespace, which is included in the Microsoft.AspNet.Web.Optimization NuGet package. As such, Scripts.Render also support JavaScript bundles (see http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification).



来源:https://stackoverflow.com/questions/17701781/what-is-the-difference-between-scripts-render-and-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!