YSLOWに基づいてページがGZIPされていない、または収縮していない問題をデバッグしようとしています。私はサーバ上で失敗したリクエストログを有効にしてしまい、なぜ圧縮していないのか失敗した理由を見ることができました。それはすでに圧縮されていると思います。IIS 8.5での圧縮が成功しませんでした.AlreadyAD_CONTENT_ENCODINGと表示されています。
DYNAMIC_COMPRESSION_NOT_SUCCESS Reason="ALREADY_CONTENT_ENCODING"
私はIISで動的および静的圧縮を有効にしていますが、web.configファイルにも以下を含めるように変更しました。私のaspxページに加えて
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
私は(これはなぜそれがエラーを引き起こしている可能性があります)gzip圧縮を実行する(ページの読み込み時に)すべてのページの前に呼び出すメソッドを持っています。
これは私が
//compress page
Compression.GZipEncodePage();
ページロードからメソッドを呼び出すと、これはページを圧縮する方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace InitialDataEntry
{
public static class Compression
{
/// <summary>
/// Sets up the current page or handler to use GZip through a Response.Filter
/// IMPORTANT:
/// You have to call this method before any output is generated!
/// </summary>
public static void GZipEncodePage()
{
HttpResponse Response = HttpContext.Current.Response;
if (IsGZipSupported())
{
string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
if (AcceptEncoding.Contains("deflate"))
{
Response.Filter = new System.IO.Compression.DeflateStream(Response.Filter,
System.IO.Compression.CompressionMode.Compress);
Response.AppendHeader("Content-Encoding", "deflate");
}
else
{
Response.Filter = new System.IO.Compression.GZipStream(Response.Filter,
System.IO.Compression.CompressionMode.Compress);
Response.AppendHeader("Content-Encoding", "gzip");
}
}
// Allow proxy servers to cache encoded and unencoded versions separately
Response.AppendHeader("Vary", "Content-Encoding");
}
/// <summary>
/// Determines if GZip is supported
/// </summary>
/// <returns></returns>
public static bool IsGZipSupported()
{
string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
string IsPartial = HttpContext.Current.Request.Headers["x-microsoftajax"];
if (!string.IsNullOrEmpty(AcceptEncoding) &&
AcceptEncoding.Contains("gzip") || AcceptEncoding.Contains("deflate"))
//Just checking to see if this is a partial page update
if (string.Compare("Delta=true", IsPartial, true) == 0)
{
return false;
}
else
{
return true;
}
else
{
return false;
}
}
}
}
これが道で働いていたが、確かではない方法ですそれは停止した、しかし、私のユーザーは、ページが膨れ上がって、500kとなったものが2MBになったので、この問題を認識しました!
ご協力いただければ幸いです。
おかげで、
私はほかに、統合モードを使用しているアプリケーションプールを確認しなかった私たちは、静的および動的のための真のhttpcompressionなどurlcompressionを持っています公布。私が実装したgzipクラスを使わずにデモサイトを走らせてみましたが、まだ圧縮はありませんでした。 私はそのローカルサーバー上でWebサイトを実行すると圧縮が行われるのは面白いですが、誰もサーバー外から見てみるとすぐに圧縮されなくなります。 – Eliseo