我使用了YSlow Firefox附加組件,它返回以下結果:使用gzip壓縮組件的D級
--------------------- -------------------------------------------------- ------------------
d級上壓縮部件用gzip
有應發送壓縮
* http://localhost:63808/WebSite/BemVindo/
* http://localhost:63808/WebSite/css/Global.css?...
* http://localhost:63808/WebSite/js/Global.js?...
3個明文部件 - -------------------------------------------------- --------------------------------------
於是我開始尋找並得到了這一段代碼:
的Global.asax
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
現在我有:
上用gzip
精細壓縮部件A級,哼?問題是:Application_PreRequestHandlerExecute事件是對請求進行gzip/deflate的最佳位置嗎?
我沒有直接回答,因爲我沒有做IIS,所以我可能是錯的「最佳實踐」,但你通常* *配置此在這裏描述的Web服務器級別http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/25d2170b-09c0-45fd-8da4-898cf9a7d568.mspx?mfr=true順便說一下,當前標題「添加過期標題」相關的問題? :) – BalusC 2010-01-22 21:21:44
但我沒有控制IIS ......這段代碼實際上起作用了,但我擔心它是否會在請求開銷之前! 呵呵,我改了標題,這是另外一個問題。 – Fernando 2010-01-22 21:40:29