How do I setup IIS with a cookieless domain to improve performance?

给你一囗甜甜゛ 提交于 2020-01-11 04:25:31

问题


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?


回答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.

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.




回答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.

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?

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.




回答4:


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




回答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']);

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



来源:https://stackoverflow.com/questions/956458/how-do-i-setup-iis-with-a-cookieless-domain-to-improve-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!