我正在使用.net 3.5的IIS7上运行asp.net web应用程序。
为了提高我的Yslow分数,我正在考虑为我的静态资源实现一个无looking的域,比如图像,CSS和JavaScript。
我的网站的网址是www.mywebsite.com。
例如,静态资源的URL为static.mywebsite.com/styles.css
我想让这个变化尽可能的无缝。我在整个站点中使用相对路径。
我可以设置子目录static.mywebsite.com
但我还需要对我的应用程序进行更改。我正在寻求这方面的帮助。具有可以包含在web.config中用于URL重写的新功能。关于如何为图像/css/javascript设置static.mywebsite.com,有什么建议或想法吗?
发布于 2017-08-05 17:46:16
对于出站规则,这是可能的。此规则会将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' /> to
<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' />
https://stackoverflow.com/questions/4368987
复制相似问题