问题描述
我工作在ASP.NET MVC3企业应用程序的开发。的,我当然有不同的主布局和多视图。
I am working on an enterprise application development in ASP.NET MVC3. Of-course I have different master layouts and multiple views.
我的担忧
- 包括主版面所有JS / CSS文件可能会影响页面的性能
- 包括意见的文件(如要求)创建的重复引用(开球的jQuery /其他库)
- 更引用,越背和放大器;客户端和服务器之间来回请求 - 这反过来又影响输出页面的性能
我的思考
- 创建所需的资源的自定义列表并将其存储在ViewBag。让主布局是指该对象包括JS / CSS文件
- 或者添加链接指具有某些关键操作(一个独特的价值,以确定该页面被渲染)和动态生成所需的所有资源的输出作为一个单一的响应。和缓存为后续请求的唯一密钥的输出(inmem / staticfile)。一种自定义资源捆绑。
请分享你的想法,有什么想法和建议,欢迎!
Please share your ideas, any thoughts and suggestions are welcome!
编辑:Sep.17.2012
下面的答案更在谈论Web应用程序开发领域优化技术 - AP preciating这些问题的答案
Below answers are more talking about optimization techniques in web application development world - appreciating those answers.
我想从架构的角度来讨论,重点打造的网页渲染需要一个动态的资源集合。
I would like to discuss from an architectural perspective, focusing on creating a dynamic resource collection required by the page being rendered.
例如,在具体的意见,我想使用jQuery UI需要的jQuery-UI-1.8.11.min.js,在某些观点我想用MVC3阿贾克斯要求MicrosoftMvcAjax.js和jquery.unobtrusive -ajax.min.js
For example, in specific views I would like to use jQuery UI which requires jquery-ui-1.8.11.min.js, and in certain views I would like to use MVC3 ajax which requires MicrosoftMvcAjax.js and jquery.unobtrusive-ajax.min.js
我不希望包括总纲永久的参考,这将导致加载这些JS的所有意见。而我想包括JS运行时文件的动态。
I don't want to include permanent reference in master layout, which will result in loading these js for all views. Rather I would like to include the js files dynamic during runtime.
希望这可能会更加清晰!
Hope this might have added clarity!
感谢您的帮助 - 维诺德
Thanks for the help - Vinod
推荐答案
您需要考虑先降低你的下载大小:
You need to think about reducing your download size first:
- 把所有的JS和CSS后的文件成为可能。这是因为客户端只能打开(大部分浏览器现在支持更多,信息您的JS和CSS。
- putting all your js and css into as few files as possible. This is because a client can only open (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.
一旦你得到这个下降到一个合理的规模,那么你可以考虑一下以上。要下载,内容前期量最小,所以在主。这将提高性能,因为那么客户端可以缓存它。缓存是一件好事,这将停止其要求每次访问一个网站上的网页时JS和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.
您可能还需要考虑采用HTTP到期标头。
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
同时不要把你的js在viewbag。这是在服务器上不必要的开销和载荷。只是在你的网页添加一个参考!
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!
我刚刚碰到过这样的,如果你要注入JS和CSS但保持高速缓存功能后,你这是什么可以做大致是:
I've just come across this, which might do roughly what your after if you want to inject js and css but keep the caching functionality:
MVC4现在支持
这篇关于什么是包括的js / css文件在企业应用架构的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!