3

My website installed in the Microsoft's Azure portal. My website using asp.net and framework(sitecore cms). It's C#.

I checked my website using gtmetrix. It recommends using cookie-free domains.

I want to try it, But I'm confused as to how to set that up under Azure portal. I'm afraid that will bring down the server. How do I do this?

1

I do not know Azure or Sitecore, however, I did do some poking around and this is what I found.

While it appears that some sitecore cookies can be disabled such as analytics, I see no reference to disabling the cookies for login and other management aspects of the CMS.

As far as Azure is concerned, the only reference to what you are asking is for static sites.

And while I am not entirely sure what you are trying to achieve as far as your website is concerned, this is not clear, it appears that the use of Sitecore will require cookies.

On Use cookie-free domains, it appears the recommendation for cookie free domains is for statics sites.

You may not be able to have a cookie free domain using Sitecore.

  • cookie free domains are typically for static assets. You can host your images, CSS, JS, where your cookies don't need to get sent for those resources and it saves some bytes. It is an optimization that makes sense only if you have tons of data stored in cookies (like 1 to 4k of data in your cookies) – Stephen Ostermiller Sep 15 at 9:55
  • @StephenOstermiller I had host my images, css and js. Look at this : postimg.cc/p5N8pkn3. Seen I save the files in the content folder. Does not call an external link. That is my test result on gtmetrix – Success Man Sep 15 at 10:33
  • @closetnoc So your point is I don't need to use cookie-free domains? – Success Man Sep 15 at 10:38
  • @SuccessMan No. My point is that the CMS itself requires cookies. I did not get into the details of serving elements of a site such as images and javascripts from sub-domains that Stephen Ostermiller describes. He is giving you good and useful detail. It would help to know what you intend with your site and how many cookies you serve now or expect. A handful of cookies should not be a big deal on any site nor is serving static content. If you have not created your site yet or your site is simple, small, or new, I would not worry about the recommendation gtmetrix made. Worry not one whit. – closetnoc Sep 15 at 14:14
  • @SuccessMan I checked one of my remaining sites using gtmetrix and evaluated it using developer tools in Chromium. Google Analytics serves 7 cookies, 3 from my domain and I have 2-3 .js and 2-3 .css files depending upon the page. I rather suspect that gtmetrix has a universal threshold where it recommends using cookie free domains. It may be advice you want to follow, however, after looking at your linked image, I am not sure I would worry about such small details yet. Cheers!! – closetnoc Sep 15 at 14:30
1

Using cookie free domains has very little to do with the web server that you are using. It is a technique for not sending cookie data when fetching static assets such as images, JavaScript, and CSS. Those assets don't typically need that data and it can make the requests slower to send lots of data to them in the cookies.

The technique only makes sense if:

  1. You use www.example.com for your site as opposed to example.com. It won't work if you use the bare domain name. When you set cookies at the bare domain, they are available to all subdomains, so it isn't possible to use a cookie free subdomain.
  2. You have lots of data in cookies. Sending 1k to 4k of cookie data to every single static asset request can add up. If you just have a 50 bytes to identify the logged in user as your cookie, this technique won't help performance much.

To use this technique you:

  1. Make sure to set cookies for www.example.com instead of example.com. This needs to be configured for both server side cookies set in your ASP code and any cookies set in your JavaScript client side code.
  2. Serve your images, CSS, and JS from a subdomain like assets.example.com, static.example.com, img.example.com, js.example.com, or css.example.com.

To do this:

  1. You need to create a subdomain and point it at your server.
  2. You need to configure the server to serve your assets at this domain.
  3. You need to change all your calls to images, css, and javascript in your HTML to use a full URL of the subdomain.
  4. You need to ensure cookies are created just for www..
  5. You may need to delete any old cookies that are not set at www.

There isn't much here that is specific to IIS and ASP. To set the cookie domain from ASP code, use this StackOverflow example: Set Domain on ASP Session Cookie. For JavaScript, use this: Creating a JavaScript cookie on a domain and reading it across sub domains. For setting up subdomains under IIS, see How to set up subdomains on IIS 7.

  • In the event that you serve cookies to your bare domain (e.g., because you want multiple subdomains to share cookies), you can still serve your images using a completely separate, cookie-free domain. – Brian Sep 26 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.