Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:01:50+00:00 2026-05-26T03:01:50+00:00

I wanted to get your opinion about managing scripts in ASP .NET MVC. There

  • 0

I wanted to get your opinion about managing scripts in ASP .NET MVC. There are 2 problems I am particularly curious about:

  1. Tracking script include dependencies of views
  2. Managing and minifying view scripts

Just like in many projects my views are composed of several partial views and editor templates. I like to keep the scripting relating to these views in the same code entity e.g.

SigningKeysForm partial view should have its own JQuery/JQueryUI scripts.

Which means any view which renders this partial view should include JQuery/JQueryUI script files.

Also another issue is when a view is composed of several such partial views, it means the javascipt in the partial views will be in several locations in the generated html.

My current approach to these problems is exploiting the top down parsing of views in ASP .Net MVC.

For tackling first problem I define a HtmlHelper extension to include a script e.g.

<% Html.RequireScript(Scripts.JQuery); %>

This way in each partial view and view I explicitly call out which scripts are required. The implementation of this method is to create a HashSet on current HttpContext and add the required script there.

In my master page I have another HtmlHelper extension which checks the HttpContext and renders the script include tags e.g:

<%=Html.RenderScriptIncludeTags()%>

This way I can track the requirements of views and render only the required script includes.

For the view scripts I am employing a similar approach. I use a custom Asp .Net user control which instead of rendering its content stores the script content into a buffer on HttpContext e.g:

 <mvc:script runat="server">
     $(function(){
          alert("Hello " + "<%=Model.Name%>");
     });
 </mvc:script>

Again in the Master view I have a HtmlHelper extension which minifies (if needed) the stored scripts and renders them e.g:

  <%=Html.RenderScripts()%>
 </body>

I think this works as a solution, but it requires the script includes and scripts to be in the bottom of the master page. This means the script includes are not in the head section.

I want to know if there are better ways to manage the script requirements and in view page scripts with ASP .NET MVC.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:01:50+00:00Added an answer on May 26, 2026 at 3:01 am

    Have you thought about using an existing tool that does this sort of thing, like Cassette (previously called Knapsack)?

    Cassette automatically sorts, concatenates, minifies, caches and versions all your JavaScript, CoffeeScript, CSS, LESS and HTML templates.

    I haven’t personally used it (yet), but it looks pretty good, and seems like it should do exactly what you need (and more). Worth noting there is a small cost for commercial use.

    EDIT: Now released under MIT licence 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on an ASP.NET 3.5 project, and I wanted to know your
I wanted to get your opinions on the easiest way to track changes that
I wanted to start a discussion about the details that you cover in your
I wanted to get a general idea from other RoR coders out there as
I wanted to get your opinions on the merits of different AMQP implementations to
I just wanted to share this Query class and get your thoughts on it.
Wanted to get some consensus around a UI feature I'm working on right now.
Just wanted to get an idea for ways (web) developers get round the short
If I wanted to get a pilot project off the ground using Microsoft PixelSense,
When I wanted to get Android source code, I knew that I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.