如何使用无Cookie域设置IIS以提高性能?

时间:2021-03-17 04:19:16

I was reading in google's documentation their new pagespeed plugin, that they recommend using cookieless domains to improve performance:

我正在谷歌的文档中阅读他们的新的pagespeed插件,他们建议使用无Cookie域来提高性能:

Static content, such as images, JS and CSS files, don't need to be accompanied by cookies, as there is no user interaction with these resources. You can decrease request latency by serving static resources from a domain that doesn't serve cookies.

静态内容(例如图像,JS和CSS文件)不需要伴随cookie,因为没有用户与这些资源交互。您可以通过从不提供cookie的域提供静态资源来减少请求延迟。

Does anybody know how to do this in IIS?

有人知道如何在IIS中执行此操作吗?

5 个解决方案

#1


What the Google article is suggesting is that you serve all your static content from another domain where cookies are not initially set by that serving domain.

Google文章建议您提供来自其他域的所有静态内容,其中Cookie最初不是由该服务域设置的。

Cookies are set in two ways - by session cookies (e.g. by ASP or ASP.NET requests) or explicitly by your application.

Cookie以两种方式设置 - 通过会话cookie(例如通过ASP或ASP.NET请求)或由您的应用程序明确设置。

These will be posted back TO the server on each subsequent request for the domain that set the cookie (regardless of whether the request is for static or dynamic content) thus increasing the request payload.

这些将在设置cookie的域的每个后续请求(无论请求是针对静态还是动态内容)上回发到服务器,从而增加请求有效负载。

What you're doing by having a second domain to serve static content (HTML, CSS, Images etc) is making cookie free requests because no initial cookie would be set in the first place for that domain.

通过让第二个域提供静态内容(HTML,CSS,图像等),您正在做的事情是提供无cookie请求,因为首先不会为该域设置初始cookie。

In IIS it's your application, ISAPI Filter or ISAPI extension that will add a cookie. If your IIS server is not intercepting requests for static content (because this is usually handled by the kernel mode http.sys driver) then no cookies will be added to the response. It's only further up the request pipeline that cookies come into play.

在IIS中,它是您的应用程序,ISAPI筛选器或ISAPI扩展,它将添加cookie。如果您的IIS服务器没有拦截静态内容请求(因为这通常由内核模式http.sys驱动程序处理),则不会将任何cookie添加到响应中。它只是在请求管道中进一步发挥作用。

So basically there isn't a way to explicitly configure cookie-less domains in IIS.

所以基本上没有办法在IIS中显式配置无cookie域。

#2


If you simply put all your static resources into, for instance, static.mysite.com, and if you never set any cookies in that domain, then the browser will never send a cookie when retrieving a resource from your static domain.

如果您只是将所有静态资源放入例如static.mysite.com中,并且如果您从未在该域中设置任何cookie,那么在从静态域中检索资源时,浏览器将永远不会发送cookie。

That's all Google is saying. There's nothing to configure, just to organize.

这就是谷歌所说的。没有什么可以配置,只是为了组织。

#3


AFAIK google analytics sets cookie for all subdomains, so it would be useless if you are using analytics?

AFAIK谷歌分析为所有子域设置cookie,因此如果您使用分析,它将毫无用处?

I've experienced this also, you'd have to use a different domain altogether to avoid analytics/adsense cookies being set. Using static.yourdomain.com won't cut it.

我也经历过这种情况,你必须完全使用不同的域来避免设置分析/ adsense cookie。使用static.yourdomain.com不会削减它。

Here's to hoping Google will change their analytics cookies so that we won't all have to buy new domains to serve cookie-less content.

这是希望谷歌改变他们的分析cookie,以便我们不必全部购买新域来提供无cookie内容。

#4


AFAIK google analytics sets cookie for all subdomains, so it would be useless if you are using analytics?

AFAIK谷歌分析为所有子域设置cookie,因此如果您使用分析,它将毫无用处?

#5


Here's an example using the Google Analytics asynchronous tracking code, of how to set the domain for tracking: _gaq.push(['_setAccount', 'UA-XXXXXXX-x'],['_setDomainName', 'www.example.com'],['_trackPageview']);

以下是使用Google Analytics异步跟踪代码的示例,说明如何设置要跟踪的域:_gaq.push(['_ setAccount','UA-XXXXXXX-x'],['_ setDomainName',''www.example.com' ],[ '_ trackPageview的']);

Here's an example using the previous version of tracking code:

以下是使用以前版本的跟踪代码的示例:

var pageTracker = _gat._getTracker("UA-XXXXXXX-x");
pageTracker._setDomainName("www.example.com");
pageTracker._trackPageview();

and here's what Google has to say about this: Google Analytics & Cookies

这就是谷歌对此的看法:Google Analytics&Cookies

#1


What the Google article is suggesting is that you serve all your static content from another domain where cookies are not initially set by that serving domain.

Google文章建议您提供来自其他域的所有静态内容,其中Cookie最初不是由该服务域设置的。

Cookies are set in two ways - by session cookies (e.g. by ASP or ASP.NET requests) or explicitly by your application.

Cookie以两种方式设置 - 通过会话cookie(例如通过ASP或ASP.NET请求)或由您的应用程序明确设置。

These will be posted back TO the server on each subsequent request for the domain that set the cookie (regardless of whether the request is for static or dynamic content) thus increasing the request payload.

这些将在设置cookie的域的每个后续请求(无论请求是针对静态还是动态内容)上回发到服务器,从而增加请求有效负载。

What you're doing by having a second domain to serve static content (HTML, CSS, Images etc) is making cookie free requests because no initial cookie would be set in the first place for that domain.

通过让第二个域提供静态内容(HTML,CSS,图像等),您正在做的事情是提供无cookie请求,因为首先不会为该域设置初始cookie。

In IIS it's your application, ISAPI Filter or ISAPI extension that will add a cookie. If your IIS server is not intercepting requests for static content (because this is usually handled by the kernel mode http.sys driver) then no cookies will be added to the response. It's only further up the request pipeline that cookies come into play.

在IIS中,它是您的应用程序,ISAPI筛选器或ISAPI扩展,它将添加cookie。如果您的IIS服务器没有拦截静态内容请求(因为这通常由内核模式http.sys驱动程序处理),则不会将任何cookie添加到响应中。它只是在请求管道中进一步发挥作用。

So basically there isn't a way to explicitly configure cookie-less domains in IIS.

所以基本上没有办法在IIS中显式配置无cookie域。

#2


If you simply put all your static resources into, for instance, static.mysite.com, and if you never set any cookies in that domain, then the browser will never send a cookie when retrieving a resource from your static domain.

如果您只是将所有静态资源放入例如static.mysite.com中,并且如果您从未在该域中设置任何cookie,那么在从静态域中检索资源时,浏览器将永远不会发送cookie。

That's all Google is saying. There's nothing to configure, just to organize.

这就是谷歌所说的。没有什么可以配置,只是为了组织。

#3


AFAIK google analytics sets cookie for all subdomains, so it would be useless if you are using analytics?

AFAIK谷歌分析为所有子域设置cookie,因此如果您使用分析,它将毫无用处?

I've experienced this also, you'd have to use a different domain altogether to avoid analytics/adsense cookies being set. Using static.yourdomain.com won't cut it.

我也经历过这种情况,你必须完全使用不同的域来避免设置分析/ adsense cookie。使用static.yourdomain.com不会削减它。

Here's to hoping Google will change their analytics cookies so that we won't all have to buy new domains to serve cookie-less content.

这是希望谷歌改变他们的分析cookie,以便我们不必全部购买新域来提供无cookie内容。

#4


AFAIK google analytics sets cookie for all subdomains, so it would be useless if you are using analytics?

AFAIK谷歌分析为所有子域设置cookie,因此如果您使用分析,它将毫无用处?

#5


Here's an example using the Google Analytics asynchronous tracking code, of how to set the domain for tracking: _gaq.push(['_setAccount', 'UA-XXXXXXX-x'],['_setDomainName', 'www.example.com'],['_trackPageview']);

以下是使用Google Analytics异步跟踪代码的示例,说明如何设置要跟踪的域:_gaq.push(['_ setAccount','UA-XXXXXXX-x'],['_ setDomainName',''www.example.com' ],[ '_ trackPageview的']);

Here's an example using the previous version of tracking code:

以下是使用以前版本的跟踪代码的示例:

var pageTracker = _gat._getTracker("UA-XXXXXXX-x");
pageTracker._setDomainName("www.example.com");
pageTracker._trackPageview();

and here's what Google has to say about this: Google Analytics & Cookies

这就是谷歌对此的看法:Google Analytics&Cookies