涅槃和.NET合并文件 [英] Minifying and combining files in .net

查看:121
本文介绍了涅槃和.NET合并文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看周围实施我的JavaScript / CSS的一些性能优化。特别是希望达到缩小和这样的完美组合。我在.NET / C#的Web应用程序开发

I am looking at implementing some performance optimization around my javascript/css. In particular looking to achieve the minification and combining of such. I am developing in .net/c# web applications.

我有一对夫妇的选择和寻找反馈每个:

I have a couple of options and looking for feedback on each:

首先就是这个聪明的工具,我碰到扢来到它通过视觉工作室结合,minifies等 - > http://chirpy.codeplex.com / 这是一个Visual Studio中添加,但因为我是在团队环境中,这个工具心不是理想的。

First one is this clever tool I came across Chirpy which via visual studio combines, minifies etc -> http://chirpy.codeplex.com/ This is a visual studio add in but as I am in a team environment, this tool isnt ideal.

我的下一个选项是使用MSBuild任务(http://yuicompressor.codeplex.com/)来缩小文件,也将它们结合起来(可能从XML文件需要结合什么读)。虽然这工作与缩小精细,值得关注我的是,我将不得不保持什么必须结合这可能是一个头痛的问题。

My next option is to use an Msbuild task (http://yuicompressor.codeplex.com/) to minify the files and also combine them (maybe read from an xml file what needs to be combined). While this works for minifying fine, the concern I have is that I will have to maintain what must be combined which could be a headache.

第三选择是使用MSBuild任务只是使用一些辅助类为缩小文件并在运行时,结合在每页的基础的文件。这将结合文件,给它一个名称,并添加一个版本吧。

3rd option is to use msbuild task just for the minifying and at runtime using some helper classes, combine the files on a per page basis. This would combine the files, give it a name and add a version to it.

任何其他的选择,我可以考虑的?我用最后的选择值得关注的是,它可能有性能问题,因为我必须打开从本地驱动器的文件,阅读其内容,然后结合这些文件。这是在运行时处理的很多。我一直在寻找类似Squishit - https://github.com/jetheredge/SquishIt/downloads 这minifies文件在运行时间,但我想看看在编译时这样做。

Any other options I could consider? My concern with the last option is that it may have performance issues as I would have to open the file from the local drive, read its contents and then combine the files. This is alot of processing at run time. I was looking at something like Squishit - https://github.com/jetheredge/SquishIt/downloads This minifies the files at run time but I would look at doing this at compile time.

所以,我的方法的任何反馈将是巨大的?如果第三个方案不会导致性能问题,我领先朝它。

So any feedback on my approaches would be great? If the 3rd option would not cause performance issues, I am leading towards it.

推荐答案

我们做了什么。具体来说,我们使用雅虎衣压缩机,其中有一个.NET库版本,你可以在你的应用程序引用。

We have done something similar with several ASP.NET web applications. Specifically, we use the Yahoo Yui compressor, which has a .NET library version which you can reference in your applications.

我们采取的方法是在运行时生成必要的合并/ minified的文件。我们都包裹着这样的逻辑成一个ASP.NET控件,但是这是没有必要依赖于您的项目。

The approach we took was to generate the necessary merged/minified files at runtime. We wrapped all this logic up into an ASP.NET control, but that isn't necessary depending on your project.


  • 第一次请求一个页面制作,我们通过包括JS和CSS文件的列表处理。在一个单独的线程(毫不拖延原始请求返回),然后我们合并了包括文件放在一起(1 JS,1 CSS),然后应用衣压缩机。

  • 然后将结果写入到磁盘在未来

  • 在随后的请求作出快速参考,页面首先查找缩小的版本。如果找到了,它只是提供这些了。如果不是,则经过该过程再次

由于部分结冰蛋糕:


  • 为了调试,如果查询字符串?调试=真实存在,合并/缩小的资源被忽略,原来的单个文件供应,而不是(因为它可能很难调试优化JS)

我们已经发现这个过程中工作出色。我们建立它变成一个库,以便所有的ASP.NET网站可以利用。生成后脚本可以变得很复杂,如果每个页面都有不同的相关性,但在运行时可以很容易地确定这一点。而且,如果有人需要做一个快速解决一个CSS文件,他们可以这样做,删除文件的合并版本中,这一过程将自动重新开始,而不需要做编译后期处理的MSBuild或南特。

We have found this process to work exceptionally well. We built it into a library so all our ASP.NET sites can take advantage. The post-build scripts can get complicated if each page has different dependencies, but the run-time can determine this quite easily. And, if someone needs to make a quick fix to a CSS file, they can do so, delete the merged versions of the file, and the process will automatically start over without need to do post-build processing with MSBuild or NAnt.

这篇关于涅槃和.NET合并文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆