Hi guys:
I've done some web based projects. In those days, I met a lot of difficulties(questions, confusions) and most of them can be figured out with help. But till now a really important question is still there, even with asking some experienced developers. The question is: When one functionality can be implemented with both server side codes and client side scripting(javascript). Which one should be preferred?
I give a simple instance:
To render a dynamic html page, I can format the page in server side with code(PHP, python) and use ajax fetch the formatted page and render it directly. (more logic in server side, less logic in client side).
And I can also use ajax fetch the data(not formatted, json) and use client side script to format the page and render it with more processing. (server side gets the data from db or elsewhere, return to client with json or xml. more logic in client side and less logic in server).
So how can I decide which one is better? Which one is with better performance? Why? which one is more user-friendly?
I'm wondering, with the browser's js engine evolving, js can be interpreted with less time. So I should prefer client side scripting?
I'm also wondering, with hardware's evolving, the server's performance will grow and the cost will decrease, so I should prefer server side scripting?
EDIT:
With the answers, I want to give a brief summary.
Pro of client side:
- better user expeience
- save network bandwidth(decrease cost)
- scalability(with boom of PVs, the growth won't grow so much as the server side logic)
Pro of server side:
- security issues
- better availability and accessiblity (mobile device, old browsers, SEO)
- expand easily(we can add more servers but we can't make the browser faster)
It seems that we need to balance these two approaches when facing a specific scenario. But how? What's the best practice?
IMO, I will use client side logic except the following conditions:
- security critical
- special groups(no javascript enabled/mobile devices, and others)