4

I am getting the information from the user. Then I am to sort the information (Alphanumerically), and give it back to the user again, hence not saving it to the database.

I am able to use either JavaScript (you could even count on jQuery), or PHP to do the sorting. Since the data might contain many lines, I am wondering about approaches below for the sorting:

let's say I tokenize all the lines using an array called lines

  • in JavaScript lines.sort();
  • in PHP sort($lines);

I am very keen to know if client-side or server-side would be doing this any differently, mainly in terms of speed. Also, if accuracy is important, then would they be any different at all? Please explain why.

2
  • jquery sort is speedy as it is client side load. For server side sorting we need to find from whole data not only from display in current page for pagination Commented Dec 18, 2015 at 7:01
  • 1
    There are so many possiblities there, for example if user has good PC and browser then it should be faster on client side because there is no need to call server side is it? On the other hand if you want to put your operations on server then you don't depend on user's browser Commented Dec 18, 2015 at 7:03

2 Answers 2

4

1) jQuery sort() is speedy as it has client side load.

2) For server side sorting we need to find from whole data not only from display in current page for pagination.

For Server side sorting is best for:

  • Large data set

  • Faster initial page load

  • Accessibility for those not running javascript

Client side sorting is best for:

  • Small data set

  • Faster subsequent page loads

  • Ability to let the user sort without loading page

That makes difference between server side sorting and client side.

Sign up to request clarification or add additional context in comments.

3 Comments

A very brief and good answer. Although I would like to know why would you say Small data set for Client side? Because we do not trust the client's browser? Or mainly because Server side is faster in operations?
if I have more then 10k cells (10 columns x 1000 rows) then I should probably enable server side processing instead of leaving it up to the client. This is especially true on older machines with shitty slow JavaScript engines.
For a Large data set we perform pagination to get record and that needs sorting from full data set requires server side sorting.
2

It would depend on the situation. Javascript means client side load. So if the client has a slow system it might take longer. But server side means you would have to get the data into php (either database or by request etc.) and after the sort back to the client.

One other thing to think about is that php is controlled. You can assure the output is the same. In Javascript it should be the same on every system. But different browsers could generate different results on sort.

1 Comment

Very well explained. "But different browsers could generate different results on sort", I definitely did not know about this. Could you please provide with a little example or link on this? Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.