What is server and client side code?

Dani AI

Generated

A few practical follow-ups to the basics already posted by and , and the IDE clarification from and . Rather than restating what client- and server-side mean, the points below show what those differences imply day-to-day: where secrets and validation must live, how to inspect requests/responses, and how modern stacks change the tradeoffs.

Never rely on client-side checks for security. Client-side validation is useful for user experience, but any authorization, input validation, or business rules that matter for correctness or safety must be enforced on the server; treat all client data as untrusted and log validation failures for investigation. (top10proactive.owasp.org)

To see what the browser actually received and what’s running where, use the browser DevTools Network and Console tabs rather than only “View Source.” A common pattern: the browser sends a fetch/XHR for data and the server returns JSON; the server-side handler does the authoritative checks. Example (minimal):

fetch('/api/check-email', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email })
})
  .then(r => r.json())
  .then(data => console.log(data));

app.post('/api/check-email', (req, res) => {
  const { email } = req.body;
  // perform server-side validation and respond with result
  res.json({ valid: isValidEmail(email) });
});

Server-side code runs in an environment the user never downloads; what the browser sees is only the server’s response. Use server logs and request tracing when debugging server logic. (devdoc.net)

Modern choices matter: client-side rendering (SPAs) gives snappier in-page interactions but pushes rendering work to the browser; server-side rendering (or hybrid approaches) can improve initial load, accessibility, and search-engine visibility. JavaScript can run on both sides (Node/Express is a common server-side option), but the rule of thumb stays: keep secrets, heavy data access, and authoritative logic on the server; keep UI responsiveness and non-sensitive formatting on the client. (developer.mozilla.org)

Recommended Answers

All 7 Replies

Client Side: This is code/routines that are not processed at all by the server. Code is written in scripts (javascript usually) - plain text commands that instruct the client to do something. Generally used for performing dynamic effects, such as image rollovers, or displaying message boxes, or even validation of data entered into a form (i.e. email address is in the format of an email address ... contains the @ symbol).

Server Side This is code/routines executed only on the server. Code can be written in scripts as well (vbscript usually), but in the case of ASP.Net this is the compiled lanuages like C# / VB.Net. Used for processing content and returning data.

i.e.
You call up a webpage and a message box appears saying Welcome to "my site". This is client side. It did not require any request from the server to have that message box appear. That code was run on your computer/browser. But the page you requested displays a list of movies playing in your town. That list was populated/retrieved through a call to the Database (located at the City movie repository...or whatever) i.e. the server to retrieve that data for your town.

Hope that helps.
:cool:

Server side is code executed by the web server. Client side is code executed by the web browser of the person viewing the site. JavaScript and HTML are examples of client-side markup.

Open your ASP.NET Project,
You'll have two mode,
1.HTML
2.Design

a.Click the HTML,
You'll see HTML and Javascript code.You can code the client side codes there.Its executed on the Client browser.

b.Now come back to Design View and double click design window,Now you be in Code behind(),this is server side code.

Now execute your project,Hit F5 and a Internet explorer will be loaded,right click on the Internet Explorer and choose VIEW SOURCE.

You can see how similar your HTML code in you notepad looks when you compare it with HTML code in step a.

I thought I'll give you a practical explanation which will help you understand more.

Hope it helps

Letscode: that isn't quite right. The "HTML" view in the VS.NET IDE isn't really HTML. It's ASP.NET code, or "aspx" code. Here you'll find the declaratives used by ASP.NET, along with the code-behind, to generate HTML. In other words, this isn't client-side code. What you see is still processed by the server.

The HTML View was rather misleading when people say client script is written in Javacript and HTML.

YES you are right tgeer.The HTML view present in VS is NOT client side scripting.

My apologies for typing something wrong,Thats not my intension.

The HTML view has an HTML format BUT its not exactly the client side code.

ASP.NET generates the client side code for that current project. .

ASP.Net also does some fancy stuff like adding an hidden form field to a WebForm, called "__VIEWSTATE" to maintain state.

Thanks for the responses. I have a better understanding of the differences between the two. :cheesy:

thanks.. now iam very clear about it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.