如何使用无 cookie 域设置 IIS 以提高性能?
我在谷歌的文档中阅读了他们的新 pagespeed 插件,他们建议使用无 Cookie 域名来提高性能:
静态内容,例如图像、JS 和 CSS 文件,不需要附带 cookie,因为用户无需与这些资源交互。 您可以通过从不提供 cookie 的域提供静态资源来减少请求延迟。
有人知道如何在 IIS 中执行此操作吗?
I was reading in google's documentation their new pagespeed plugin, that they recommend using cookieless domains to improve performance:
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.
Does anybody know how to do this in IIS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Google 文章建议您从另一个域提供所有静态内容,其中 cookie 最初不是由该服务域设置的。
Cookie 有两种设置方式 - 通过会话 Cookie(例如通过 ASP 或 ASP.NET 请求)或通过您的应用程序显式设置。
这些将在每个后续请求设置 cookie 的域时发回服务器(无论请求是针对静态内容还是动态内容),从而增加请求负载。
通过使用第二个域来提供静态内容(HTML、CSS、图像等),您所做的就是发出无 cookie 的请求,因为首先不会为该域设置初始 cookie。
在 IIS 中,您的应用程序、ISAPI 过滤器或 ISAPI 扩展将添加 cookie。 如果您的 IIS 服务器没有拦截静态内容的请求(因为这通常由内核模式 http.sys 驱动程序处理),则不会将 cookie 添加到响应中。 只有在请求管道的更上游,cookie 才会发挥作用。
因此基本上没有办法在 IIS 中显式配置无 cookie 域。
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.
Cookies are set in two ways - by session cookies (e.g. by ASP or ASP.NET requests) or explicitly by your application.
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.
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.
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.
So basically there isn't a way to explicitly configure cookie-less domains in IIS.
例如,如果您只是将所有静态资源放入 static.mysite.com,并且从未在该域中设置任何 cookie,则浏览器在从静态域检索资源时将永远不会发送 cookie。
这就是谷歌所说的一切。 无需配置任何内容,只需组织即可。
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.
That's all Google is saying. There's nothing to configure, just to organize.
我也经历过这种情况,您必须完全使用不同的域来避免设置分析/adsense cookie。 使用 static.yourdomain.com 不会减少它。
希望谷歌能够改变他们的分析 cookie,这样我们就不必购买新的域名来提供无 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.
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,所以如果你使用分析,它就没用了?
AFAIK google analytics sets cookie for all subdomains, so it would be useless if you are using analytics?
以下是使用 Google Analytics 异步跟踪代码的示例,说明如何设置跟踪域:
_gaq.push(['_setAccount', 'UA-XXXXXXX-x'],['_setDomainName', 'www.example.com'],['_trackPageview']);
这是一个使用的示例以前版本的跟踪代码:
这是 Google 对此的说法:谷歌分析和 Cookies
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']);
Here's an example using the previous version of tracking code:
and here's what Google has to say about this: Google Analytics & Cookies