Idempotency and cookies?



  • I'm still not 100% clear on idempotency.  I have a site that is kind of heavy with graphics, and I provide a text-only version of the site, that needs to work correctly on Pocket IE (and also might be preferred for dial-up visitors).  At the bottom of each page is a link that will take you to the
    text-only or rich version of the site (whichever one you aren't
    viewing).  The "view text-only" link uses a query string with something like "?textonly=T" or "?textonly=F".

    So here's the idempotency question:  say a user goes to "page.php?textonly=T".  When the page is loaded, a "textonly" cookie is set, so that the whole site will be viewed that way (the user doesn't have to pass the "?textonly" query to each page on the site).  Does this violate idempotency?  Will any cookies be set by a prefetch?  If cookies are not set/used, there is no side-effect.  But if the browser prefetches the textonly page and sets the cookie, the next page the user goes to will show up text only.  But I can't imagine the browser setting a cookie on a prefetch, and no spiders use cookies, so I don't think this violates idempotency.... Am I right?



  • Whether or not it violates idempotency depends on how you label the link. If you have a link that says "view site in text-only mode", that perhaps has alternate information (via the title attribute) that explains that this is a semi-permanent, site-wide switch, and provide a corresponding "view site in graphic-heavy mode" link, then no, you're not violating idempotency. As for prefetching, browsers should not respond to http response headers such as Set-Cookie until the page is actually loaded. If the browser is changing state in response to a page that has not been visited by the user, the browser needs an overhaul.



  • @carfield said:

    I think it will. Consider the following scenario: Assume the default is not text only if no parameter set (textonly=F). User visit front page (http://site.com) and set to use textonly=T, then he go to second page (http://site.com/page1.html) without textonly parameter, and he get the text only page and bookmarkit. Later, he delete the cookie ( may be auto by browser as the number of cookie exceed limit ). Then he go to (http://site.com/page1.html) using the bookmarks, now, he will get the non-text only page.

    Same URL, 2 difference return, I guess this violate idempotency. However, not a big issue in my opinions if every page have a link to let user to switch interface. In fact, it is difficult to have 100% idempotency for web application.

    Not sure if this is the correct way to understand idempotency at web application, please let me know if I am wrong, thx~



    Don't be so strict. A lot of people, including you and me, look at http://www.thedailywtf.com but get different content all the time. Do you really want this site to be idempotent?



  • @carfield said:

    I think it will. Consider the following scenario: Assume the default is not text only if no parameter set (textonly=F). User visit front page (http://site.com) and set to use textonly=T, then he go to second page (http://site.com/page1.html) without textonly parameter, and he get the text only page and bookmarkit. Later, he delete the cookie ( may be auto by browser as the number of cookie exceed limit ). Then he go to (http://site.com/page1.html) using the bookmarks, now, he will get the non-text only page. Same URL, 2 difference return, I guess this violate idempotency. However, not a big issue in my opinions if every page have a link to let user to switch interface. In fact, it is difficult to have 100% idempotency for web application. Not sure if this is the correct way to understand idempotency at web application, please let me know if I am wrong, thx~

    Hmm... interesting point.

    Well, you could always use URL re-writing for your text/notext issue. Instead of http://site.com/page.asp?text-only, you could have http://site.com/textonly/page.php, or http://textonly.site.com/page.jsp.



  • That's a good idea.. I really like the textonly.site.com/page solution.  It would be really easy to parse the current URL to determine which page to show.  Now I've just gotta learn how to set up my server to do that...



  • @kipthegreat said:

    That's a good idea.. I really like the textonly.site.com/page solution.  It would be really easy to parse the current URL to determine which page to show.  Now I've just gotta learn how to set up my server to do that...

    I believe that textonly.site.com/page would require DNS changes. site.com/textonly/page may be easier to manage.



  • Every managed hosting or domain registration system I have used has had a way of simply adding subdomains by pointing them to a subfolder of the main document root. For example, on my server the photos. subdomain points to 'document_root/photos' so they can be browsed as:

    mydomain.com/photos

    or as

    photos.mydomain.com

    It takes a matter of seconds to configure this in most hosting setups, and coupled with a bit of .htaccess magic (or equivelant if using IIS or whatever) a redirect could be done to the 'real' content with the right flag added.

    That's how I'd do it, anyway :-)  h



  • @kipthegreat said:

    That's a good idea.. I really like the textonly.site.com/page solution.  It would be really easy to parse the current URL to determine which page to show.  Now I've just gotta learn how to set up my server to do that...

    Just check whether or not your host offers subdomain.

    Dreamhost for example offers an unlimited number of subdomains for free.




Log in to reply