如何压缩数据
1. 我的主机使用 IIS 7,而 IIS 没有我访问设置的权限。 现在如何 web.config 或其他我发送了 js/css/aspx 来应用 Gzip。
2.如何为iis6启用etag
如何为我的网站启用此功能 这不起作用(Yslow)
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
编辑
global.asax 中的这段代码很好用,但 Yslow 仍然显示不使用 Gzip?
void Application_PreRequestHandlerExecute(对象发送者,EventArgs e) { HttpApplication 应用程序 = 发送者作为 HttpApplication; 字符串acceptEncoding = app.Request.Headers["Accept-Encoding"]; 流 prevUncompressedStream = app.Response.Filter;
if (!(app.Context.CurrentHandler is Page ||
app.Context.CurrentHandler.GetType().Name == "SyncSessionlessHandler") ||
app.Request["HTTP_X_MICROSOFTAJAX"] != null)
return;
if (acceptEncoding.Contains("gzip") )
return;
acceptEncoding = acceptEncoding.ToLower();
if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
{
// gzip
app.Response.Filter = new GZipStream(prevUncompressedStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
}
else if (acceptEncoding == null || acceptEncoding.Length == 0)
{
// defalte
app.Response.Filter = new DeflateStream(prevUncompressedStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "deflate");
}
}
1.
My host uses IIS 7 and IIS is not my right to access settings.
Now how do the web.config or the other I sent a js/css/aspx to apply the Gzip.
2.how can enable etags for iis6
how can enable this for my web site
this not work(Yslow)
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
Edit
this code in gloabal.asax good work but still Yslow show does not use Gzip??
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
string acceptEncoding = app.Request.Headers["Accept-Encoding"];
Stream prevUncompressedStream = app.Response.Filter;
if (!(app.Context.CurrentHandler is Page ||
app.Context.CurrentHandler.GetType().Name == "SyncSessionlessHandler") ||
app.Request["HTTP_X_MICROSOFTAJAX"] != null)
return;
if (acceptEncoding.Contains("gzip") )
return;
acceptEncoding = acceptEncoding.ToLower();
if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
{
// gzip
app.Response.Filter = new GZipStream(prevUncompressedStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
}
else if (acceptEncoding == null || acceptEncoding.Length == 0)
{
// defalte
app.Response.Filter = new DeflateStream(prevUncompressedStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "deflate");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在代码中实现压缩是错误的方法;我理解您的情况,我确信这很困难,但我会考虑搬到另一位房东。
你的意思是当你在本地测试时它可以工作,但当它部署到主机时却不起作用?我确实见过一些代理(例如公司网关)从线路中删除了“接受编码gzip”,因此这可能是值得考虑的事情。
I believe that implementing compression in code is the wrong approach; I understand your situation and I am sure it's difficult, but I would consider moving to another host.
Do you mean that it works when you test locally, but not when it's deployed to the host? I've definitely seen some proxies (e.g. corporate gateways) remove the "accept-encoding gzip" from the wire, so that might be something to consider.