Search code examples
html-tablequery-stringsession-storage

Should I store basic information (like table sort or page number) in query string or session storage?


I am developing a web application (a dashboard of some sort), and on some pages I have a couple of data tables. Each data table has its own page number, filter and sort. Although the data is fetched asynchronously in the background (hence the page does not need to reload), but I need to store these information (page, filter, sort) so it can be persistent for example during a page refresh. As far as I know, there are two ways to store these information:

  • In the session storage (local storage is not an option, because I don't want these information to be persistent between sessions)
  • In the query string

Up until now I used to store these information in the query string because I thought it has some advantages: e.g. the user can copy, bookmark, or share the URL with a colleague to discuss some data which they find interesting (for example on the 10th page of a table after performing some filtering and sorting). With the session storage I cannot do this

But now I am extending the abilities of the filter function, and now the information is quite long to use in the query string, and may even exceed the limit (I think 2048 characters, right?). And also there may be more than a couple of tables on each page, and therefore the query string would even become longer.

So first I wanted to know what is the best practice in this situation

And second, is that feature (being able to copy/bookmark/share the page as is) really that important, or not?

Note: please note that the information that I'm talking about is nothing secret or sensitive. It's just table page number, table filter and table sort


Solution

  • The 2048 limit seems that's not really an actual limit, see What is the maximum possible length of a query string?

    About the best approach - I've personally always hated that most "new websites" do not support the feature you care about, so I'd personally encourage you to support it!

    And finally about the exact mechanism, firstly the query string approach will keep working for a lot longer than 2048 characters, but I can see that copy&pasting it might be unwieldy and depending on the media to share the URL it can introduce mistakes.

    So, from the user's perspective, I think the best experience would be given by storing those searches on the backend side and enabling a shorter URL for permalinking/sharing/bookmarking.

    This new URL could be obtained by the user via a specific UI button (Share/Permalink) so you save the search in that moment and return the URL, or (best experience but harder and costlier to implement) you can be saving it continuously and sending back to the UI the generated URL and use Javascript to replace the URL for the nicer version (either always or just when people copy it).

    Also consider: it may be good enough to just keep using the query string :-)