Search filter, should I do this on the client side or on the server side?

I have a search form that returns a list of results, I also have a filter area where the user can filter the results (price, etc.). My question is: should I do filtering through javascript on the client side or should I do it on the server within MYSQL?

The problem is that filtering will have quite a few levels, so setting it into mysql select can become quite tedious.

+4
source share
4 answers

It depends on whether you use pagination or not.

If you do not paginate the search result, but return each row to the client, you should filter the client side, since you know that all clients are data.

If your search result is paginated, simply showing the first search results, for example, .10, it is necessary that the server side includes a filter containing all the broken pages that are not yet on the client.

+7
source

It really depends on the nature of your application:

  • how much data is there?
  • how often do you request it?
  • how often do i need to reload the page?

I. facebook sends you the entire list of friend names, so when you type someones in the comments, the client application notices this (and offers you automatic completion). This was done on the client side because:

  • the entire amount of data is relatively small (1000 friend names * 20 bytes each ~ = 20 KB of data, less than most images on a website, gzip and even less)
  • he asked for a LOT almost every time someone presses a key in a text box
  • most of the things in the application can be done without leaving or reloading the page: data should only be loaded once.

Generally speaking, letting the client do more work means your application can scale more easily, as the more users you get, the more โ€œprocessor powerโ€ you get.

+4
source

It must be server-side in your SQL.

Something like SELECT * WHERE price> 100

If you do this on the client side, you need to send a lot of data from the server to the client.

0
source

You must understand the consequences if you place them on the client side.

  • You may need to transfer a lot more data over the Internet than you want.

  • You may not be able to use some good MySQL stuff, such as an index or cache, to optimize your results. These well-designed and proven features are always better than yours.

However, I think itโ€™s normal to do this on the client side if you are healthy with these consequences.

0
source

Source: https://habr.com/ru/post/1384475/


All Articles