为静态资源设置无Cookie域
我在.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的任何提示或想法?
这是可能的出站规则。此规则将重写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' />
好问题,但恕我直言,你不应该这样做,以提高你的YSlow得分了。我只会做,如果你相信你会有一个性能改善。用户不会在意你的yslow得分是多少。他们需要一个快速页面。当然,有分数的相关性:速度,但不要做只是为了增加分数。 :) – Joe 2010-12-06 17:42:59