如何实现GZip压缩COM pression在ASP.NET? [英] How to implement GZip compression in ASP.NET?

查看:95
本文介绍了如何实现GZip压缩COM pression在ASP.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现GZip压缩COM pression为我的asp.net页面(包括我的CSS和JS文件)。我尝试以下code,但它只COM presses我的.aspx页面中(找到它从 YSlow的

I am trying to implement GZip compression for my asp.net page (including my CSS and JS files). I tried the following code, but it only compresses my .aspx page (found it from YSlow)

HttpContext context = HttpContext.Current;
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip");
HttpContext.Current.Response.Cache.VaryByHeaders["Accept-encoding"] = true;

以上code仅COM pressing我的.aspx页面中code(标记),而不是CSS和JS文件,这是作为外部文件。
请告诉我怎样可以用code在ASP.NET中实现GZip压缩COM pression(因为我是共享宿主服务器上,我没有访问IIS服务器配置)。而且在上述code,我没有得到最后两行,所以才使用的,什么是这些线路的目的。请解释!

The above code is only compressing my .aspx page code (markup) not the CSS and JS files which is included as external files. Please tell me how can I implement GZip compression in ASP.NET using code (because I am on shared hosting server where I don't have access to IIS Server configurations). And also in the above code I am not getting the last two lines, why they are used and what's the purpose of these lines. Please explain!

感谢

推荐答案

有关COM pressing JS&安培; CSS文件你确实有处理,在IIS的水平,因为这些文件直接输出而不ASP.NET运行时。

For compressing JS & CSS files you actually have to handle that at the IIS level, since these files are rendered directly without the ASP.NET runtime.

您可以做一个JSX&安培;在IIS CSSX扩展名映射到ASPNET_ISAPI.DLL再趁你的拉链code,但IIS可能会为你做这个工作做得更好。

You could make a JSX & CSSX extension mapping in IIS to the aspnet_isapi.dll and then take advantage of your zip code, but IIS is likely to do a better job of this for you.

内容编码头告诉它需要渲染前解压缩内容的浏览器。有些浏览器是足够聪明,反正这个号码,基于内容的形状,但它最好只告诉它。

The content-encoding header tells the browser that it needs to unzip the content before rendering. Some browsers are smart enough to figure this out anyway, based on the shape of the content, but it's better to just tell it.

在接受编码缓存设置是有这样的gzip压缩内容的缓存版本将不会被发送到请求的纯文本/ HTML浏览器。

The Accept-encoding cache setting is there so that a cached version of the gzipped content won't be sent to a browser that requested only text/html.

这篇关于如何实现GZip压缩COM pression在ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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