2010-12-06 290 views
1

我在.net 3.5上運行IIS7上的asp.net web應用程序。爲靜態資源設置無Cookie域

爲了提高我的Yslow分數,我正在爲我的靜態資源(如圖像,CSS和JavaScript)實施一個無Cookie域。

我的網站的網址是www.mywebsite.com。

所以靜態資源例如有static.mywebsite.com/styles.css

我想使這個改變儘可能無縫的URL。我在整個網站使用相對路徑。

我可以設置subdirectoy static.mywebsite.com

但我也需要作出改變,以我的應用程序。我正在尋找這方面的幫助。使用可以包含在web.config中的新功能進行URL重寫。有關我如何能夠爲images/css/javascript設置static.mywebsite.com的任何提示或想法?

+2

好問題,但恕我直言,你不應該這樣做,以提高你的YSlow得分了。我只會做,如果你相信你會有一個性能改善。用戶不會在意你的yslow得分是多少。他們需要一個快速頁面。當然,有分數的相關性:速度,但不要做只是爲了增加分數。 :) – Joe 2010-12-06 17:42:59

回答

0

這是可能的出站規則。此規則將重寫js,css,jpg和png到static.mywebsite.com。

<outboundRules rewriteBeforeCache="true"> 
    <rule name="CDN-01-css" preCondition="CheckHTML" stopProcessing="true"> 
     <match filterByTags="Link" pattern="/(.*\.css)" /> 
     <action type="Rewrite" value="http://static.mywebsite.com/{R:1}" /> 
    </rule> 
    <rule name="CDN-01-js" preCondition="CheckHTML" stopProcessing="true"> 
     <match filterByTags="Script" pattern="/(.*\.js)" /> 
     <action type="Rewrite" value="http://static.mywebsite.com/{R:1}" /> 
    </rule> 
    <rule name="CDN-01-jpg" preCondition="CheckHTML" stopProcessing="true"> 
     <match filterByTags="Img" pattern="/(.*\.jpg)" /> 
     <action type="Rewrite" value="http://static.mywebsite.com/{R:1}" /> 
    </rule> 
    <rule name="CDN-01-png" preCondition="CheckHTML" stopProcessing="true"> 
     <match filterByTags="Img" pattern="/(.*\.png)" /> 
     <action type="Rewrite" value="http://static.mywebsite.com/{R:1}" /> 
    </rule> 
    <preConditions> 
     <preCondition name="CheckHTML"> 
     <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 
     </preCondition> 
    </preConditions> 
</outboundRules> 

例如:

它會自動改變你的HTML輸出

<link rel='stylesheet' id='social-logos-css' href='/wp-content/plugins/jetpack/_inc/social-logos/social-logos.min.css?ver=1' type='text/css' media='all' />

<link rel='stylesheet' id='social-logos-css' href='http://static.mywebsite.com/wp-content/plugins/jetpack/_inc/social-logos/social-logos.min.css?ver=1' type='text/css' media='all' />