What is the difference between “@Scripts.Render” and “”?

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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.

Method 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).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x