首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为静态资源设置无cookieless域

为静态资源设置无cookieless域
EN

Stack Overflow用户
提问于 2010-12-07 01:06:46
回答 1查看 501关注 0票数 1

我正在使用.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,有什么建议或想法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-08-05 17:46:16

对于出站规则,这是可能的。此规则会将js、css、jpg和png重写为static.mywebsite.com。

代码语言:javascript
复制
<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' />

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4368987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档