Optimization of persistent state storage in cookies

Optimization of persistent state storage in cookies

mcarrowdmcarrowd Posts: 2Questions: 0Answers: 0
edited November 2012 in General
In my project I have two large datatables which save its state in cookies. Average size of data to store is about 1500-2000 bytes. Saving state of one table cause cookie expiration of another due to 4 KiB limit. In current implementation, old cookies are expired in order of creation time. I think that it is necessary to expire cookie of current table at first if exists.

Here is a path.

[code]
@@ -4517,6 +4517,7 @@

if ( iNewCookieLen+document.cookie.length+10 > 4096 ) /* Magic 10 for padding */
{
+ var equalCookieIdx = -1;
for ( var i=0, iLen=aCookies.length ; i= 0 )
+ {
+ var old = aOldCookies[equalCookieIdx];
+ document.cookie = old.name+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
+ aParts.join('/') + "/";
+ aOldCookies.splice(equalCookieIdx, 0);
}

// Make sure we delete the oldest ones first
[/code]

Replies

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin
    A good idea this, but cookies are being dropped form DataTables 1.10 in preference of localStorage which doesn't have the problems of cookies :-). Also saves about 1.5K of size on DataTables core - win/win!

    Allan
  • mcarrowdmcarrowd Posts: 2Questions: 0Answers: 0
    Good news about local storage, anyway I will have to use it if I need third table :-)
This discussion has been closed.