Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

razor

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.

like image 541
Guilherme Oderdenge Avatar asked Jul 17 '13 13:07

Guilherme Oderdenge


People also ask

What is Scripts render?

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.

Where do I put script render?

Render on the head section of your page. Doing so would let the browser render the page faster because it waits for all CSS files to load before rendering the page. I would also advise you to put your @Scripts. Render before the closing tag of the page body.

What is script bundle?

The ScriptBundle class represents a bundle that does JavaScript minification and bundling. You can create style or script bundles in BundleConfig class under App_Start folder in an ASP.NET MVC project.

How to create a script bundle in asp net mvc?

How to create and use a ScriptBundle in ASP.NET MVC? JavaScript bundles can be created only in ~/App_Start/BundleConfig. cs page. To create a JavaScript bundle we use ScriptBundle class by passing virtual path as parameter in the constructor.


1 Answers

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.

like image 183
Tamim Al Manaseer Avatar answered Sep 28 '22 22:09

Tamim Al Manaseer