Search code examples
jquerycookiesbrowserdatatablelimit

How to overcome the browser limit for cookies?


I am working on an application that uses jQuery's Datatables. And I am also using the Column Filters plugin. One of the requirements is to be able to persist the state of the Datatables and thus the column filters too.

However, the problem is that the application can have hundreds, thousands of tables and for each table a separate cookie. With this a user can very quickly break the limit of the amount of cookies a browser is allowed to store (around 300). The number is a guess, the point is that it is a small number and if I was to turn bStateSave on for every generated table, sooner or later (More sooner than later) a user will break that limit and thus break the app.

What alternative solutions are there for this issue? Storing the state in the database is bad because the application is already constantly querying millions/billions of data.


Solution

  • Datatables uses localStorage and sessionStorage by default, so unless you have to support an older browser like ie 6/7, then you should not worry about running into cookie limitations.

    https://datatables.net/examples/basic_init/state_save.html

    Used in conjunction with stateDuration set to 0, your state will be stored indefinitely. https://datatables.net/reference/option/stateDuration

    That being said, if you will also eventually be limited with localStorage by the browser...

    The only viable solution when you reach these limits is to save the state on the server using stateLoadCallback and stateSaveCallback.