blowery.Web.HttpCompress 和 ICSharpCode.SharpZipLib 在Subtext中應用。
在上篇文章中,我推薦了High Performance Web Sites 的14條原則,昨天看到第4條--Gzip Components,聯系起 Subtext中用到的第三方組件
blowery.Web.HttpCompress 和 ICSharpCode.SharpZipLib。
Subtext中正是遵循這一原則,避免每次請求都要創建一個新的XML document ,對Rss feed進行了壓縮並緩存。
class BaseSyndicationHandler實現IHttpHandler接口功能
核心代碼分析:

protected virtual void ProcessFeed()


...{

if(RedirectToFeedBurnerIfNecessary())

return;

//請求者是FeedBurner的話處理後直接跳出


if(IsLocalCacheOK())


...{

Send304();


return;

}


// 本地緩存並未過期不處理,發送304狀態碼,跳出


if(!IsHttpCacheOK())


...{

Feed = BuildFeed();//創建feed,並賦予LastModifIEd等相應屬性

if(Feed != null)


...{

if(UseDeltaEncoding && Feed.ClIEntHasAllFeedItems)


...{

Send304();

return;

}


//Delta Encoding只發送小部分更改的請求,這樣可以減少發送內容

Cache(Feed);

}

}


WriteFeed();//采用Gzip壓縮格式

}
再說一下web.config的配置(由於Subtext進行了整合,所以還是說下通用的配置)

<configSections>


<sectionGroup name="blowery.web">


<section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>


</sectionGroup>


</configSections>




<blowery.web>


<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>



<httpModules>


<add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>


</httpModules>
控件下載地址及說明文檔:
blowery.Web.HttpCompress :http://www.icsharpcode.Net/OpenSource/SharpZipLib/Download.ASPx
http://codedocs.rainbowbeta.com/blowery.Web.HttpCompress.Html
ICSharpCode.SharpZipLib:
http://blowery.org/code/HttpCompressionModule.Html