What is the best practice to include js/css files in an enterprise application framework?

后端 未结 1 949
感情败类
感情败类 2021-02-20 12:18

I am working on an enterprise application development in ASP.NET MVC3. Of-course I have different master layouts and multiple views.

My concerns

<
1条回答
  •  梦如初夏
    2021-02-20 13:08

    You need to think about reducing your download size first:

    • putting all your js and css into as few files as possible. This is because a client can only open 2 HTTP channels (most browsers now support more, info here) at any one time, all file downloads after this are queued until the previous ones finish downloading.
    • minify your js and css.

    Once you've got this down to a reasonable size then you can think about the above. You want to download, the smallest amount of content upfront, so in the master. This will improve performance because then the client can cache it. Caching is a good thing, this stops the client having to request the js and css every time they visit a page on your site.

    You might also want to think about applying HTTP expiry headers.

    Yahoo do a good site on lots of these ideas: http://developer.yahoo.com/performance/rules.html

    Also don't put your js in the viewbag. This is unnecessary overhead and load on the server. Just add a reference in your pages!

    MVC4 now supports bundling

    0 讨论(0)
提交回复
热议问题