0

I'm right now using asp.net mvc 4.5 in my projects . I like the way asp.net MVC is designed and works, but i am struggling with the script and styles sheet management.

Every page of my project use different style sheet and scripts files so i can not add all the scripts and style sheet file in the layout file as it is not the good technique & increase page loading time , i want to add those related files on each page where they are needed. suggest me a good solution

2 Answers 2

1

You could register a section in your layout:

@RenderSection("scripts", required: false)

and then in each view override this section and define any custom scripts related to it:

@section scripts {
    <script type="text/javascript" src="@Url.Content("~/scripts/myscript.js")"></script>
}

Using this same technique you could define another section for the custom stylesheets.

This being said, if you take advantage of the built-in bundling and minification mechanism, it might be more effective to have a single minified and compressed file rather than multiple files because the browser will need to make separate HTTP request to retrieve them.

Sign up to request clarification or add additional context in comments.

2 Comments

thanx please give me little description about the working of @render section method also
Sure, you may checkout the following link: blogs.msdn.com/b/marcinon/archive/2010/12/15/…
0

i would recommend using ClientDipendancy Framework.

https://github.com/Shazwazza/ClientDependency

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.