title: Grade D on Compress components with gzip
body: <p>I used the YSlow Firefox add-on and it return the follow result:</p>
  
  <p>-----------------------------------------------------------------------------------------<br>
  Grade D on Compress components with gzip</p>
  
  <p>There are 3 plain text components that should be sent compressed</p>
  
  <pre><code>* http://localhost:63808/WebSite/BemVindo/
  * http://localhost:63808/WebSite/css/Global.css?...
  * http://localhost:63808/WebSite/js/Global.js?...
  </code></pre>
  
  <p>-----------------------------------------------------------------------------------------<br>
  So I started to search and got this piece of code:</p>
  
  <p>Global.asax</p>
  
  <pre><code>Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
  
      Dim Response As HttpResponse = HttpContext.Current.Response
      Dim AcceptEncoding As String = HttpContext.Current.Request.Headers("Accept-Encoding")
  
      If Not String.IsNullOrEmpty(AcceptEncoding) AndAlso AcceptEncoding.Contains("gzip") OrElse AcceptEncoding.Contains("deflate") Then
          If AcceptEncoding.Contains("deflate") Then
              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")
          End If
      End If
  
      Response.AppendHeader("Vary", "Content-Encoding")
  
  End Sub
  </code></pre>
  
  <p>And now I have:</p>
  
  <p>Grade A on Compress components with gzip</p>
  
  <p>Fine, hum? The question is: Is the Application_PreRequestHandlerExecute event the best place to gzip/deflate the requests?</p>