为静态资源设置 cookieless 域

发布于 2024-10-06 10:46:55 字数 424 浏览 2 评论 0原文

我正在 IIS7 上使用 .net 3.5 运行 asp.net Web 应用程序。

为了提高我的 Yslow 分数,我正在考虑为我的静态资源(例如图像、CSS 和 JavaScript)实现一个无 cookie 域。

我网站的 URL 是 www.mywebsite.com。

例如,静态资源的 URL 为 static.mywebsite.com/styles.css

我希望使此更改尽可能无缝。我在整个网站中使用相对路径。

我可以设置子目录 static.mywebsite.com

但我还需要对我的应用程序进行更改。我正在寻求这方面的帮助。可以将新功能包含在 web.config 中以进行 URL 重写。关于如何为 images/css/javascript 设置 static.mywebsite.com 有任何提示或想法吗?

I am running an asp.net web application on IIS7 with .net 3.5.

To improve my Yslow score I am looking at implementing a cookieless domain for my static resources such as images, CSS and JavaScript.

My site's URL is www.mywebsite.com.

So static resources will for example have a URL of static.mywebsite.com/styles.css

I would like to make this change as seamless as possible. I use relative paths throughout the site.

I can set up the subdirectoy static.mywebsite.com

But I also need to make the changes to my application. I am looking for help with this. With the new functionality that can be included in the web.config for URL rewriting. Any tips or ideas as to how I may be able to set up static.mywebsite.com for images/css/javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2024-10-13 10:46:55

出站规则是可能的。此规则会将 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

It is possible with outbound rules. This rules will rewrite js,css,jpg and png to 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>

For example:

It will automatically change your output 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' />

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文