网站速度优化模块HttpCompressionModule

简介:
为了优化网站的访问速度,准备采用 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 - [url]http://slingfive.com/demos/browserCaps/[/url]  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 后访问速度有明显改善。
 





本文转自 张善友 51CTO博客,原文链接:http://blog.51cto.com/shanyou/75262,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
Python
理解模块功能
理解模块功能
25 8
|
17天前
|
人工智能 大数据 5G
400G光模块已经部署,需求将进一步扩大
2023年底,电信运营商完成400G OTN试验网设备部署,标志着400G技术大规模部署的开端。400G传输技术日趋成熟,预计2024年实现长距离商用。400G光模块在提升数据传输效率、降低能耗方面发挥关键作用,适应云计算、大数据、AI对高效算力的需求。光纤技术行业显现复苏态势,400G光模块部署成为数据中心发展的必然,支持新兴技术发展。随着5G、云计算等技术进步,对高速光模块需求激增,推动光纤行业创新与市场扩张。
16 2
|
8月前
|
Web App开发 缓存 JSON
可以用到项目的优化网站加载速度方案
可以用到项目的优化网站加载速度方案
56 0
|
11月前
|
数据采集 算法 数据可视化
MMdetection框架速成系列 第03部分:简述整体构建细节与模块+训练测试模块流程剖析+深入解析代码模块与核心实现
按照抽象到具体方式,从多个层次进行训练和测试流程深入解析,从最抽象层讲起,到最后核心代码实现,希望帮助大家更容易理解 MMDetection 开源框架整体构建细节
506 0
|
前端开发
前端学习案例15-HMR(热模块更新)
前端学习案例15-HMR(热模块更新)
56 0
前端学习案例15-HMR(热模块更新)
|
数据采集 JavaScript 容灾
配置模块设计
配置模块设计
172 0
配置模块设计
|
存储 SQL 算法
搜索引擎模块设计与实现——集群模块1
搜索引擎模块设计与实现——集群模块
搜索引擎模块设计与实现——集群模块1
|
存储 算法 搜索推荐
搜索引擎模块设计与实现——集群模块2
搜索引擎模块设计与实现——集群模块
hook+ts业务开发思路5-完成列表页面的编写
hook+ts业务开发思路5-完成列表页面的编写
46 0
hook+ts业务开发思路5-完成列表页面的编写
ts重点学习13-ts优势和缺点优化
ts重点学习13-ts优势和缺点优化
69 0