Forum Moderators: open

Message Too Old, No Replies

Speed of checking cookie's name

checking if such a cookie exist

         

Ian2k8

5:11 am on Mar 29, 2008 (gmt 0)

10+ Year Member



If I want to check if guest has a cookie named "mysettings" using the following method.

if(document.cookie.match("mysettings"))

Is this method efficient when the website has more than 100 pages and guest has to do this checking on every page?

I once wonder if the checking speed will be seriously slow down when guest's computer has stored a lot of cookies, but because this method checks the cookie that was set at the same domain, so it is the fastest method. Right?

[edited by: Ian2k8 at 6:05 am (utc) on Mar. 29, 2008]

JAB Creations

8:43 am on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the old chunk of JavaScript I used to use to find a specific cookie however I highly recommend using serverside language to do this instead.

- John

var $theme = getCookie("theme"); function getCookie(Name) { var search = Name + "="; var CookieString = document.cookie; var result = null;
if (CookieString.length > 0) { offset = CookieString.indexOf(search); if (offset != -1) { offset += search.length; end = CookieString.indexOf(";", offset)
if (end == -1) {end = CookieString.length}; result = unescape(CookieString.substring(offset, end))}}return result;}

Ian2k8

1:17 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



Thank you, John.

Why do you highly recommend using server-side language?

JAB Creations

1:24 pm on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Webkit (Safari, Omniweb, and now iCab 4+) does not play nice with cookies (via JavaScript).

- John

[edited by: JAB_Creations at 1:24 pm (utc) on Mar. 30, 2008]

Ian2k8

2:00 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



I see. Thank you.