Client and Server
In web development, the client is the web browser on the user's device (such as Chrome), while the server is the computer that stores and delivers the web pages. Client-side scripting means the script code runs on the user's browser, not on the server. This lets a page respond instantly without having to reload the whole page from the server.
Key idea
JavaScript is the most widely used client-side scripting language. It runs inside the browser and can change the content of an HTML page, respond to user actions, and validate form data.
Running Scripts in a Page
JavaScript code is placed in an HTML page using the <script> tag. When the browser loads the page, it also runs that script. Scripts can respond to events such as a button click through handlers like onclick.
Example
The following script shows a message when the button is clicked:
<button onclick="greet()">Click</button>
<script>
function greet() {
alert("Welcome!");
}
</script>The greet() function runs inside the browser, not on the server.
Advantages of Client-Side Scripting
Because scripts run on the user's browser, client-side scripting:
- Gives an instant response without waiting for the server.
- Reduces the load on the server and bandwidth use.
- Allows simple form validation before data is sent.
However, client-side scripting is not suitable for tasks needing high security or database access, which are better handled by server-side scripts.
Remember
Client = browser; server = the computer that stores the pages. JavaScript is a client-side scripting language that runs inside the browser to make pages interactive.