Note that there are some explanatory texts on larger screens.

plurals
  1. POClient-side logic OR Server-side logic?
    text
    copied!<p>I've done some web-based projects, and most of the difficulties I've met with (questions, confusions) could be figured out with help. But I still have an important question, even after asking some experienced developers: <strong>When functionality can be implemented with both server-side code and client-side scripting (JavaScript), which one should be preferred?</strong></p> <p>A simple example: </p> <p>To render a dynamic html page, I can format the page in server-side code (PHP, python) and use Ajax to fetch the formatted page and render it directly (more logic on server-side, less on client-side).</p> <p>I can also use Ajax to fetch the data (not formatted, JSON) and use client-side scripting to format the page and render it with more processing (the server gets the data from a DB or other source, and returns it to the client with JSON or XML. More logic on client-side and less on server).</p> <p>So how can I decide which one is better? Which one offers better performance? Why? Which one is more user-friendly?</p> <p>With browsers' JS engines evolving, JS can be interpreted in less time, so should I prefer client-side scripting?</p> <p>On the other hand, with hardware evolving, server performance is growing and the cost of sever-side logic will decrease, so should I prefer server-side scripting?</p> <p><strong>EDIT:</strong></p> <p>With the answers, I want to give a brief summary.</p> <p><strong>Pros of client-side logic:</strong></p> <ol> <li>Better user experience (faster).</li> <li>Less network bandwidth (lower cost).</li> <li>Increased scalability (reduced server load).</li> </ol> <p><strong>Pros of server-side logic:</strong></p> <ol> <li>Security issues.</li> <li>Better availability and accessibility (mobile devices and old browsers).</li> <li>Better SEO.</li> <li>Easily expandable (can add more servers, but can't make the browser faster).</li> </ol> <p>It seems that we need to balance these two approaches when facing a specific scenario. But how? What's the best practice?</p> <p>I will use client-side logic except in the following conditions:</p> <ol> <li>Security critical.</li> <li>Special groups (JavaScript disabled, mobile devices, and others).</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload