I am trying to debug the issue of why my pages are not being GZIP'ed or deflated according to YSLOW. I ended up enabling Failed Request Logs on the server and was able to see the failed reason of why it is not compressing, it thinks it is already compressed.
DYNAMIC_COMPRESSION_NOT_SUCCESS Reason="ALREADY_CONTENT_ENCODING"
I have enabled dynamic and static compression in IIS, I have also changed the web.config file to include the following.
<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"/>
In addition on my aspx page I have a method I call before every page (on page load) to run gzip compression (this might be why it is causing the error).
This is how I call the method from the page load
//compress page
Compression.GZipEncodePage();
And this is the method that compresses the page
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;
}
}
}
}
This used to work by the way, but not sure when it stopped, however my users realized the issue as the pages got bloated in size and what used to be 500k is now 2mb!
Any help would be greatly appreciated.
Thanks,