Php vs javascript information processing speed

I have a database containing strings in the format: "Key: value | key: value | key: value | key: value"

Due to some other reasons, I cannot have key value pairs stored in the database.

Should I use PHP to split the string and pass it to the javascript framework, or,
Should I pass the complete string to javascript and parse its javascript.

+4
source share
3 answers

In theory, it would be acceptable. In practice, I was inclined to do as many repetitive jobs on the server as possible. If you think about it, from the point of view of which it can be done faster, you KNOW how quickly your server can do it. Resources remain (relatively) constant.

The execution of this in javascript depends on the client environment. Using a web application, the client environment is infinitely diverse. You never know how much memory the client will have available, so it is impossible to assess how effectively they can analyze data. 99% of your customers may be fine, but the other 1% get a blocked browser when using your script.

The safest bet should always use known amounts as much as possible. In this case, this is your known amount - do the work there.

+6
source

It is more or less careless. However, the possible length of the sting should be considered. If you know that there will be quite a lot of NVPs, then it might be wise to just transfer as one line and split it at the other end (provided that it will have the same glue for attaching the parts).

0
source

If the string is data specific and the string is created from the backend, it would be better to allow PHP to manipulate it. Usually you want to limit most of your javascript to interact with the user interface / on the client side, unless of course you use JS on the server.

0
source

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


All Articles