关于asp.net网站 gzip压缩 优化问题
本帖最后由 wxf809602518 于 2013-02-22 18:43:18 编辑
本人对于优化就是菜鸟,以前从没接触过。求各位大哥帮忙啊, 我用asp.net做的网站 已经发布到ftp上。现在想对网站进行gzip压缩 ,提高浏览速度。由于条件限制不能用IIS进行GZIP压缩,只能写代码啦, 在网上也搜到了代码如下:
public sealed class CompressionModule : IHttpModule
{
void IHttpModule.Dispose()
{
// Nothing to dispose;
}
void IHttpModule.Init(HttpApplication context)
{
if (BlogSettings.Instance.EnableHttpCompression)
{
context.PreRequestHandlerExecute +=
new EventHandler(context_PostReleaseRequestState);
}
}
private const string GZIP = "gzip";
private const string DEFLATE = "deflate";
void context_PostReleaseRequestState(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
if (app.Context.CurrentHandler is System.Web.UI.Page &&
app.Request["HTTP_X_MICROSOFTAJAX"] == null)
{
if (IsEncodingAccepted(DEFLATE))
{
app.Response.Filter =
new DeflateStream(app.Response.Filter,
CompressionMode.Compress);
SetEncoding(DEFLATE);
}
else if (IsEncodingAccepted(GZIP))
{
app.Response.Filter =
new GZipStream(app.Response.Filter,
CompressionMode.Compress);
SetEncoding(GZIP);
}
}
else if (app.Context.Request.Path.Contains("WebResource.axd"))
&