I have a client-server web app I’m working on. There’s a point in the initial loading of the client-side where I need to process some JSON data from the server-side db to get it in the right format… Which essentially entails adding a bunch of empty JSON objects to it (thus making entire JSON array bigger). This formatting calculation is somewhat trivial (no need for a super-computer), so it can be done on either the client or the server.
So the 2 choices I have for implementation are:
- Format JSON data on server, send MORE data to client
- Send LESS data to client, format JSON data on client (extra client computation)
I can think of pros and cons for both choices…
- Choice #1, consistently compute the formatting, but increase number of packets that must be sent for initial load.
- Choice #2, minimize number of packets that must be sent, but add
extra computation to clients with varying or unknown performance.
Out of these 2 choices, is there a “best-practices” solution which I should typically lean towards?
That’s a good and interesting question. I’d rather choose option #1 because you’ll never know about the features of a client device. However, if your program runs on a server (normally with a powerful hardware) the processing time will be independent of the client device, which could be a mobile phone with reduced computing capabilities.