I ran into the same problem and therefore used .net compression caused by using global.asax, along with renaming static css with the .aspx extension and using url rewriting via Web.config. On top of .css.aspx I just added
<%@ Page ContentType="text/css" %>
In the rules for rewriting system.webserver Web.config configuration:
<rule name="san aspx"> <match url=".*[^/]$" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="{R:0}.aspx" /> </rule> <rule name="revert aspx"> <match url="(.*)\.aspx$"/> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="{R:1}" /> </rule>
In Application_PreRequestHandlerExecute global.asax
HttpApplication app = sender as HttpApplication; string acceptEncoding = app.Request.Headers["Accept-Encoding"]; Stream prevUncompressedStream = app.Response.Filter; if (acceptEncoding != null && acceptEncoding.Length > 0) { acceptEncoding = acceptEncoding.ToLower(); if (acceptEncoding.Contains("gzip")){ app.Response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress); app.Response.AppendHeader("Content-Encoding", "gzip"); } } Response.Cache.VaryByHeaders["Accept-Encoding"] = true;
It seems intimidating, but with building the right understanding, it works like a charm and is worth saving on SEO related to PageSpeed, as well as shared hosting. I tried with the support of my hosting provider, but instead they sold more exotic hosting packages. For forcefully compressed content such as a .svgz file, I used a separate folder and the httpProtocol system.webserver of this web.config folder I wrote:
<customHeaders> <add name="Content-Encoding" value="gzip" /> </customHeaders>
Chawathe Vipul Jan 24 '13 at 19:17 2013-01-24 19:17
source share