Skip to main content

Client-side versus server-side scripting

Short answer

Client-side scripting runs in the browser using JavaScript for validation and UI updates, while server-side scripting runs on the server using PHP or Java for database work and authentication. Server-side code is hidden and more secure but needs a round trip.

What is the difference between client-side scripting and server-side scripting? Explain with example.

Client-side scripting means scripts that are downloaded with the page and run in the user's browser (e.g. JavaScript). Server-side scripting means scripts that run on the web server, which generates the HTML sent to the browser (e.g. PHP, JSP/Servlets, ASP.NET, Node.js).

BasisClient-side scriptingServer-side scripting
ExecutionIn the browserOn the web server
LanguagesJavaScript, VBScriptPHP, Java (JSP/Servlet), Python, ASP.NET, Node.js
Source codeVisible to the user (View Source)Hidden; the user sees only the output HTML
Server loadLow; uses the client's CPUHigher; the server does the work
Response speedFast for UI actions, no round tripNeeds a request-response trip
Database accessCannot access it directlyCan connect to databases and files
SecurityLess secure; user can modify codeMore secure; code and data stay on the server
DependenceDepends on browser support/settingsIndependent of the browser
Typical usesForm validation, animation, DOM changes, AJAXAuthentication, database operations, sessions, dynamic pages

Example

Client-side (validates before sending):

<script>
function check(){
  if(document.getElementById("age").value < 18){ alert("Must be 18+"); return false; }
}
</script>

Server-side (PHP creates the page and reads the database):

<?php
$name = $_POST['name'];
echo "Welcome, " . htmlspecialchars($name);
?>

In practice both are used together: JavaScript gives quick feedback, and PHP re-validates and stores the data.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Web Technology chapter 3 questions →