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.
What I'm meaning is: when I should use one or other and why.
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.
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.
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 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With