Stopping cookies being set from a domain (aka “cookieless domain”) to increase site performance

后端 未结 4 684
暗喜
暗喜 2020-12-13 02:52

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 domai

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 03:34

    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.

    
    

提交回复
热议问题