CompressionModule

优点:开放源代码,强大的自定义功能,能压缩多种资源,能完美支持各种ajax框架!
缺点:使用复杂,仅支持asp.net2.0或以上版本!
http://www.codeproject.com/KB/aspnet/httpcompression.aspx

 

将DC.Web.HttpCompress.dll放到网站项目的bin目录,再按如下增加及修改项目的web.config

<configSections>
<sectionGroup name="DCWeb">
   <section name="HttpCompress" type="DC.Web.HttpCompress.Configuration,
      DC.Web.HttpCompress"/>
</sectionGroup>
</configSections>
<DCWeb>
<HttpCompress   compressionType="GZip">
<!--设定是否启用cachefiles功能,并指定cache目录,如果删掉这行配置的话就自动默认为false(不开启cache)-->
   <CacheSettings cacheFiles="true" path="cache"/>
<!--设定jspath及csspath,如果删除掉这行配置的话就会使用默认值-->
   <PathSettings jsPath="javascript" cssPath="css" />
<!--配置要压缩何种类型的资源,这里设定只压缩html,即只有aspx页面及*.axd资源会被压缩,其它的资源(如图片,CSS等)将不被压缩!例:如果要压缩gif,请添加<add mime="image/gif"/>,压缩jpg则添加<add mime="image/jpeg"/>-->
   <IncludedMimeTypes>
       <add mime="text/html" />
   </IncludedMimeTypes>
   <!--配置不压缩何种类型资源请使用:
   <ExcludedMimeTypes>
       <add mime="text/html" />
   </ExcludedMimeTypes>
   注意:ExcludedMimeTypes及IncludedMimeTypes只需要配置一个就可以,如果像上面那样配置ExcludeMimeTypes的话,则表明除html类型的资源外,其它资源都会被压缩-->
       <ExcludedPaths>
<!--设定不启用压缩的页面路径,下面设定了nocompress目录下的default.aspx页面将不会启用压缩功能,但其它页面则正常启用压缩-->
      <add path="~/NoCompress/Default.aspx" />
       </ExcludedPaths>
   </HttpCompress>
</DCWeb>
   <!-- The js.axd and css.axd must be enabled to allow javascript and css
   compression -->
   <httpHandlers>
<!--如果不需要使用到此功能的话可删掉此配置节-->
<add verb="*" path="js.axd,css.axd"
       type="DC.Web.HttpCompress.CompressionHandler,DC.Web.HttpCompress"/>
   </httpHandlers>
   <!-- The compression module must be enabled for the WebResource.axd to be
   compressed -->
   <httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
       System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
       PublicKeyToken=31bf3856ad364e35"/>
<!--设定启用压缩模块的参数-->
<add name="HttpCompressModule"
       type="DC.Web.HttpCompress.HttpModule,DC.Web.HttpCompress"/>
   </httpModules>


配置好后,压缩模块就可以正常工作了!
小提示:如果web.config配置了   
<CacheSettings cacheFiles="true" path="cache"/>
那么项目下就必须存在cache这个目录,否则的话会出错,如果项目不想增加这个目录,只需要将这个配置节删掉即可!

posted on 2011-08-22 13:23  Peter Zhang  阅读(420)  评论(0编辑  收藏  举报