1

So we're trying to re-imagine our web solution in an MVC fashion. Going from an old webforms based solution to working with ASP.NET MVC with a bootstrap main menu and adding functionality in the forms of widgets using HTML.Action() that calls a controller and action to fill in the information on that part of the page.

We're now thinking of how the CSS and resources that we are going to be getting for each widget separately in their own controller can be effectively used in this scenario.

If we only use HTML.Action and letting a controller add our functionality to the page, we lose our connection to the page as a whole, and we could possibly load the resource package and CSS for the same type of objects over and over again. How would one solve this and make it possible for our web portal to have knowledge over which css and resource files have already been added to the solution?

    1 Answer 1

    1

    The browser will not request a resource from your server constantly with making some significant (and not easy to find) configuration changes. This goes for CSS, javascript files, images, etc. When the web server provides the initial request to a client, it also includes an expiration time for most objects. The browser will look at that expiration time when requesting updates from the server. If the time hasn't expired, the browser will not request the same object again. This is true of all of the big browsers.

    If you configure your web server to set the timeout on everything being served to 0 or -1 (depending on what server you use), then the client will request every item every time it needs to display something. That places a huge extra load on your server.

    In an MS MVC scenario, the only place you may even want to think about setting the timeout to 0 is on your web services or web api. Most of your application is going to be sending the same thing to all of your users. And MVC is smart enough to figure out what needs to be a 0 timeout for most things.

    UPDATE

    You can dynamically add CSS to the HEAD. See this answer on StackOverflow Dynamically Add CSS To Page Via Javascript.

    2
    • We are going to utilize all available caching techniques. What Im asking is if its possible to in some fashion let each widget to be responsible for getting its css for example and still getting this information to the header element of our page. It seems that Html.Action is only top down. There is no way to ask underlying controllers what their current model contains. We want to avoid getting css-links included all throughout our webpage and just have this information collected in our page header but still let the each widget be responsible for adding the info.
      – Andreas
      CommentedFeb 14, 2014 at 10:30
    • See my updated answer.CommentedFeb 14, 2014 at 16:37

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.