停止从网域(即“无Cookie域”)设置的Cookie,以提高网站的效果 [英] Stopping cookies being set from a domain (aka "cookieless domain") to increase site performance

查看:1323
本文介绍了停止从网域(即“无Cookie域”)设置的Cookie,以提高网站的效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读 Google文档以改进网站速度。他们的一个建议是提供来自无Cookie域的静态内容(图片,CSS,JS等):


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




p>为
为静态内容保留无Cookie域,注册一个新的
域名,并配置一个CNAME记录的
数据库
将新域名指向现有的
domain A记录。配置您的web
服务器以从
新域中提供静态资源,并且不允许在
域的任何位置设置任何
cookie。在您的网页中,请参考

静态资源的网址中的域名。


非常直接的东西,除了它说:配置您的网络服务器从新域中提供静态资源,并且不允许任何cookie设置在这个域的任何地方。 从我的我们在IIS中没有允许你说提供静态资源的设置,那么如何防止ASP.NET在这个新域上设置cookie呢?



目前,即使我只是从新域名请求一个.jpg,它在我的浏览器上设置一个cookie,即使我们的应用程序的cookie设置为我们的旧域。例如,ASP.NET设置了一个.ASPXANONYMOUScookie(据我所知),我们不会告诉它。



如果这个是一个真正的新手问题,我是这个新的!



谢谢。

解决方案<



如果您没有设定网域,以仅托管诸如脚本,图像等的资源内容,它们被来自浏览器的简单HTTP-GET请求请求。这些内容应按原样提供。这将使您的域无Cookie。这不能由web服务器配置完成。 Http完全没有状态,Web服务器根本不知道cookie。 Cookie通过服务器端脚本写入或发送到客户端。 您最好的做法是在IIS应用程序上禁用asp.net,classic-asp或php脚本功能。



is。



我们有一个子域设置来提供无Cookie资源。因此,我们托管所有的图像和脚本在子域。并且从主应用程序,我们只是指向资源的url。 我们确保子网域不需要提供任何动态脚本,或者通过创建任何asp.net或php会话。

  http://cf.mydomain.com/resources/images/*.images 
http://cf.mydomain.com/resources/scripts/*.scripts
http://cf.mydomain.com/resources/styles/*.styles

从主域名我们只引用一个资源如下。

 < img src =http://cf.mydomain.com/ resources / images / logo.png/> 


I was reading in Google's documentation about improving site speed. One of their recommendations is serving static content (images, css, js, etc.) from a "cookieless domain":

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.

Google then says that the best way to do this is to buy a new domain and set it to point to your current one:

To reserve a cookieless domain for serving static content, register a new domain name and configure your DNS database with a CNAME record that points the new domain to your existing domain A record. Configure your web server to serve static resources from the new domain, and do not allow any cookies to be set anywhere on this domain. In your web pages, reference the domain name in the URLs for the static resources.

This is pretty straight forward stuff, except for the bit where it says to "configure your web server to serve static resources from the new domain, and do not allow any cookies to be set anywhere on this domain". From what I've read, there's no setting in IIS that allows you to say "serve static resources", so how do I prevent ASP.NET from setting cookies on this new domain?

At present, even if I'm just requesting a .jpg from the new domain, it sets a cookie on my browser, even though our application's cookies are set to our old domain. For example, ASP.NET sets an ".ASPXANONYMOUS" cookie that (as far as I'm aware) we're not telling it to do.

Apologies if this is a real newb question, I'm new at this!

Thanks.

解决方案

If you don't write cookies from domain, the domain will be cookie-less.

When the domain is set to host only resource content like scripts, images, etc., they are requested by plain HTTP-GET requests from browsers. These contents should be served as-is. This will make your domain cookieless. This cannot be done by web-server configuration. Http is completely state-less and web-servers have no idea about the cookies at all. Cookies are written or sent to clients via server-side scripts. The best you can do is disable asp.net, classic-asp or php script capabilities on the IIS application.

The way we do it is.

We have a sub-domain setup to serve cookie-less resources. So we host all our images and scripts on the sub-domain. and from the primary application we just point the resource by it's url. We make sure sub-domain remains cookie-free by not serving any dynamic script on that domain or by creating any asp.net or php sessions.

http://cf.mydomain.com/resources/images/*.images
http://cf.mydomain.com/resources/scripts/*.scripts
http://cf.mydomain.com/resources/styles/*.styles

from primary domain we just refer a resource as following.

<img src="http://cf.mydomain.com/resources/images/logo.png" />

这篇关于停止从网域(即“无Cookie域”)设置的Cookie,以提高网站的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆