Server Side Code
Server-side code refers to the code that runs on a web server rather than in a user's web browser. It is responsible for processing requests from clients (typically web browsers) and generating dynamic web pages or providing data to the client.
Why do we need server-side code?
Server-side code is essential in web development for several reasons:
- Security: Server-side code is not visible to the user, so it is more secure than client-side code.
- Performance: Server-side code can be used to perform computationally expensive tasks, such as data processing, without affecting the user's experience.
- Data Storage: Server-side code can be used to store data in a database, which can then be accessed by the client-side code.
- User Authentication: Server-side code can be used to authenticate users and restrict access to certain parts of the website.
- Dynamic Content: Server-side code can be used to generate dynamic web pages, which can be customized for each user.
Server-side vs. Client-side
The differences are summarized in the table below:
|Server-side Code||Client-side Code|
|Runs on a web server||Runs in a web browser|
|Has access to server resources (file system, databases, etc.).||Has access to client resources (cookies, local storage, etc.).|
|May use server-side rendering (SSR) to generate HTML on the server.||Uses client-side rendering (CSR) to generate HTML in the browser.|
|Better for SEO as content is readily available for search engines.||Worse for SEO as content is not readily available for search engines.|
|Can leverage caching and Content Delivery Networks (CDNs) for performance.||Limited control over caching, relies on browser cache.|
Unified Language: Developers can use the same language and programming paradigms throughout the entire application stack, which can lead to code reusability and easier collaboration among front-end and back-end developers.