2

I found this piece of code in all.js from Facebook's core JavaScript. Looks like the cookie has an expiration date of 04 Feb 2004, apparently the day Facebook was born. Anyone curious enough to tell me whether this piece of code really has value or just exists for historical significance.

 function j(m, n, o) {
                m = m + h.getClientID();
                var p = i && i !== '.';
                if (p) {
                    document.cookie = m + '=; expires=Wed, 04 Feb 2004 08:00:00 GMT;';
                    document.cookie = m + '=; expires=Wed, 04 Feb 2004 08:00:00 GMT;' + 'domain=' + location.hostname + ';';
                }
                var q = new Date(o).toGMTString();
                document.cookie = m + '=' + n + (n && o === 0 ? '' : '; expires=' + q) + '; path=/' + (p ? '; domain=' + i : '');
            }

From what I understand, setting an expiry date 10 years in the past doesn't really make sense to me. I might be wrong, but I am interested to know nonetheless. I think it's just one of the snippets left over by Zuck?

document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 GMT";

http://connect.facebook.net/en_US/all.js

Used JsBeautifier to make it readable: http://jsbeautifier.org/

Ali Gajani
  • 14,762
  • 12
  • 59
  • 100
  • 2
    Close(2)? I don't get it. This is a programming related question. It might be an opinion based but I am trying to get 'facts' here. I was just curious. Perhaps I should post this somewhere else? – Ali Gajani May 22 '14 at 06:36
  • 1
    I fail to understand how this post has anything to do with opinions. – bjb568 May 22 '14 at 06:39
  • @bjb568: Say that to those who voted to close this on grounds of this category: "primarily opinion based". – Ali Gajani May 22 '14 at 06:40
  • Can we have the link to the full script? – bjb568 May 22 '14 at 06:42
  • http://connect.facebook.net/en_US/all.js – Ali Gajani May 22 '14 at 06:42
  • 8
    Setting a cookie expiry date in the past effectively removes the cookie. They may have chosen that specific date out of historical significance but that's something you should ask Facebook, not StackOverflow – Phil May 22 '14 at 06:44
  • 1
    http://stackoverflow.com/q/686155/2888561 – bjb568 May 22 '14 at 06:48
  • The question is, why would Facebook choose such a place to display their historical significance. – Ali Gajani May 22 '14 at 06:49
  • 2
    Shouldn't be necessary to ask Facebook - it's not like it's an obscure reference. Februrary 4 2004 was the day thefacebook.com launched. – JimmiTh May 22 '14 at 06:50
  • 4
    @AliGajani if "the question is, why would Facebook choose such a place to display their historical significance." then how could someone except the original developer answer this in a way that isn't opinion based? I won't vote to re-close to stay out of the open/close war, but I think the close was warrented. – James Montagne May 22 '14 at 20:14
  • There were 5 close votes in the morning, and now 1. Nice, some people retracted their votes because they think this question has a potential for interesting revelation :) I am waiting to see if Facebook devs find time to answer here, let's see. Well, to be honest, no one knows why that date would be chosen. – Ali Gajani May 22 '14 at 21:23

1 Answers1

3

This is just a way of removing an old cookie. Since any date in the past would do, Wed, 04 Feb 2004 08:00:00 GMT is as good a choice as any. But since Facebook didn't exist before this date, it's the nearest date guaranteed to be in the past for every Facebook user session, so there is a kind of logic to choosing this date beyond just historical significance.

nullability
  • 10,545
  • 3
  • 45
  • 63