網站速度最佳化模組HttpCompressionModule

來源:互聯網
上載者:User

為了最佳化網站的訪問速度,準備採用HttpCompressionModule 6對傳輸資料進行壓縮,下載了HttpCompressionModule 6 , 並按照樣本程式中的web.config配置了網站的web.config。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
   <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
   <sectionGroup name="blowery.web">
         <section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>
      </sectionGroup>
     </configSections>
  <appSettings>
    <add key="FCKeditor:UserFilesPath" value="/KeyuSoftShanyou/UserFiles" />
    <add key="SearchIndexDir" value="~/index" />
  </appSettings>
 
 
  <!-- config section for my http module -->
  <blowery.web>
    <!--
   Here's an example on how to change the algorithm or compression level
   
      <compressionModule preferredAlgorithm="deflate|gzip" compressionLevel="high|normal|low"/>
   
   so, to use deflate by default, and high compression, you would use the following line
   -->
    <httpCompress preferredAlgorithm="gzip" compressionLevel="high">
      <excludedMimeTypes>
        <add type="image/jpeg"/>
        <add type="image/png"/>
        <add type="image/gif"/>
      </excludedMimeTypes>
      <excludedPaths>
        <!--<add path="NoCompress.aspx"/>-->
      </excludedPaths>
    </httpCompress>
  </blowery.web>
 
  <system.web>  
    
    
     <httpModules>
 <!-- <add type="KeyuSoftShanyou.Util.NHSessionModule, KeyuSoftShanyou" name="NHSessionModule" />-->
         <add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>
     </httpModules>
 
  
    <authentication mode="Forms">
  <forms name="shanyouCookie" loginUrl="Admin/login.aspx" protection="All" timeout="90"/>
 </authentication> 

    <authorization>  <allow users="*" />   </authorization>

    <compilation        defaultLanguage="c#"      debug="true"  />
    <customErrors   defaultRedirect="Error.aspx"  mode="RemoteOnly" />

    <trace   enabled="false"    requestLimit="10"        pageOutput="false"
        traceMode="SortByTime"
  localOnly="true"
    />

 
    <sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false"
            timeout="20"
    />

    <globalization  requestEncoding="utf-8" responseEncoding="utf-8" />
     <!-- 2003-12-03, Rob Eberhardt - http://slingfive.com/demos/browserCaps/  firefox 瀏覽器問題 -->

<browserCaps>
  <!-- GECKO Based Browsers (Netscape 6+, Mozilla/Firebird, ...) //-->
  <case match="^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+)? (?'type'[^/\d]*)([\d]*)/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)).*">
    browser=Gecko
    type=${type}
    frames=true
    tables=true
    cookies=true
    javascript=true
    javaapplets=true
    ecmascriptversion=1.5
    w3cdomversion=1.0
    css1=true
    css2=true
    xml=true
    tagwriter=System.Web.UI.HtmlTextWriter
    <case match="rv:(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*))">
      version=${version}
      majorversion=${major}
      minorversion=${minor}
      <case match="^b" with="${letters}">
        beta=true
      </case>
    </case>
  </case>
 
  <!-- AppleWebKit Based Browsers (Safari...) //-->
  <case match="AppleWebKit/(?'version'(?'major'\d)(?'minor'\d+)(?'letters'\w*))">
    browser=AppleWebKit
    version=${version}
    majorversion=${major}
    minorversion=0.${minor}
    frames=true
    tables=true
    cookies=true
    javascript=true
    javaapplets=true
    ecmascriptversion=1.5
    w3cdomversion=1.0
    css1=true
    css2=true
    xml=true
    tagwriter=System.Web.UI.HtmlTextWriter
    <case match="AppleWebKit/(?'version'(?'major'\d)(?'minor'\d+)(?'letters'\w*))( \(KHTML, like Gecko\) )?(?'type'[^/\d]*)/.*$">
      type=${type}
    </case>
  </case>
  <!-- Konqueror //-->
  <case match = "Konqueror/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'));\w*(?'platform'[^\)]*)">
    browser=Konqueror
    version=${version}
    majorversion=${major}
    minorversion=${minor}
    platform=${platform}
    type=Konqueror
    frames=true
    tables=true
    cookies=true
    javascript=true
    javaapplets=true
    ecmascriptversion=1.5
    w3cdomversion=1.0
    css1=true
    css2=true
    xml=true
    tagwriter=System.Web.UI.HtmlTextWriter
  </case>
</browserCaps>

 </system.web>
  <!-- This section contains the log4net configuration settings -->
   <log4net>  <!-- Define some output appenders -->
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
       <param name="File" value="log.txt" />
       <param name="AppendToFile" value="true" /> 
       <param name="MaxSizeRollBackups" value="2" />
       <param name="MaximumFileSize" value="100KB" /> 
       <param name="RollingStyle" value="Size" />  
       <param name="StaticLogFileName" value="true" />
       <layout type="log4net.Layout.PatternLayout">  
  <param name="Header" value="[Header]\r\n" />
  <param name="Footer" value="[Footer]\r\n" />  
  <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" /> 
       </layout>
     </appender> 
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">  
  <layout type="log4net.Layout.PatternLayout"> 
    <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />  
    </layout>  </appender>  <!-- Set root logger level to ERROR and its appenders --> 
    <root>
    <level value="ERROR" />
        <appender-ref ref="RollingLogFileAppender" /> 
        <appender-ref ref="ConsoleAppender" />
    </root> 
        <!-- Print only messages of level DEBUG or above in the packages -->
      <logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
          <level value="DEBUG" />
       </logger>
             
        <logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory"> 
             <level value="DEBUG" />
         </logger> 
     <logger name="IBatisNet.DataMapper.LazyLoadList"> 
     <level value="DEBUG" />
     </logger>
 </log4net>
 
</configuration>

使用效果:
使用HttpCompressionModule內建的Fetch工具進行測試,測試結果如下:


測試結果說明:
第一行資料是未使用HttpCompressionModule的測試結果。
第二行資料是使用deflate壓縮演算法進行壓縮後的測試結果。
第二列資料是Web伺服器傳遞到瀏覽器的檔案大小。很明顯,壓縮後傳輸資料大大減少,有效地節約了頻寬。
TTFB—首位元組平均回應時間(Gets the number of milliseconds that have passed before the first byte of the response was received.)
TTLB—末位元組平均回應時間(Gets the number of milliseconds that passed before the last byte of the response was received. )
Transit—傳輸資料到瀏覽器的時間。
從測試結果可以看出, 採用HttpCompressionModule後訪問速度有明顯改善。

 

http://www.asp.net/ControlGallery/ControlDetail.aspx?Control=696&tabindex=2

http://www.blowery.org/code/HttpCompressionModule.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.