Tuesday, August 30, 2016

Difference Between Client-Side & Server-Side

Links:

Difference Between Client-Side & Server-Side
Multiple Responses:
1.
Differences between Client-side and Server-side Scripting
Client-side Environment
The client-side environment used to run scripts is usually a browser. The processing takes place on the end users computer. The source code is transferred from the web server to the users computer over the internet and run directly in the browser.

The scripting language needs to be enabled on the client computer. Sometimes if a user is conscious of security risks they may switch the scripting facility off. When this is the case a message usually pops up to alert the user when script is attempting to run.

Server-side Environment
The server-side environment that runs a scripting language is a web server. A user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages. This HTML is then sent to the client browser. It is usually used to provide interactive web sites that interface to databases or other data stores on the server.

This is different from client-side scripting where scripts are run by the viewing web browser, usually in JavaScript. The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.

2.
I've seen questions (mainly on Stack Overflow), which lack this basic knowledge. The point of this question is to provide good information for those seeking it, and those referencing to it.

In the context of web programming, what are the differences between Server-side programming and Client-side programming? Which languages belong to which, and when do you use each of them?

Background
Web development is all about communication. In this case, communication between two (2) parties, over the HTTP protocol:
  • The Server - This party is responsible for serving pages.
  • The Client - This party requests pages from the Server, and displays them to the user. In most cases, the client is a web browser.
    • The User - The user uses the Client in order to surf the web, fill in forms, watch videos online, etc.

Each side's programming, refers to code which runs at the specific machine, the server's or the client's.

Basic Example
  1. The User opens his web browser (the Client).
  2. The User browses to http://google.com.
  3. The Client (on the behalf of the User), sends a request to http://google.com (the Server), for their home page.
  4. The Server then acknowledges the request, and replies the client with some meta-data (calledheaders), followed by the page's source.
  5. The Client then receives the page's source, and renders it into a human viewable website.
  6. The User types Stack Overflow into the search bar, and presses Enter
  7. The Client submits that data to the Server.
  8. The Server processes that data, and replies with a page matching the search results.
  9. The Client, once again, renders that page for the User to view.

Programming
Server-side Programming
Server-side programming, is the general name for the kinds of programs which are run on the Server.

Uses
  • Process user input.
  • Display pages.
  • Structure web applications.
  • Interact with permanent storage (SQL, files).

Example Languages
  • PHP
  • Python
  • ASP.Net in C#, C++, or Visual Basic.
  • Nearly any language (C++, C#, Java). These were not designed specifically for the task, but are now often used for application-level web services.

Client-side programming
Much like the server-side, Client-side programming is the name for all of the programs which are run on the Client.

Uses
  • Make interactive webpages.
  • Make stuff happen dynamically on the web page.
  • Interact with temporary storage, and local storage (Cookies, localStorage).
  • Send requests to the server, and retrieve data from it.
  • Provide a remote service for client-side applications, such as software registration, content delivery, or remote multi-player gaming.

Example languages
  • JavaScript (primarily)
  • HTML*
  • CSS*
  • Any language running on a client device that interacts with a remote service is a client-side language.”

In layman's words:

Here I will talk only about web programming.

Client side programming has mostly to do with the user interface, with which the user interacts. In web development it's the browser, in the user's machine, that runs the code, and it's mainly done injavascript, flash, etc. This code must run in a variety of browsers.

Its main tasks are:
  • validating input (Validation must be done in the server. A redundant validation in the client could be used to avoid server calls when speed is very critical.)
  • animation
  • manipulating UI elements
  • applying styles
  • some calculations are done when you don't want the page to refresh so often

The person in charge of front end programming must know:
  • javascript
  • css
  • HTML
  • basic graphic design
  • Ajax
  • maybe Flash
  • some 3rd party javascript libraries like JQuery
  • UI design
  • information design, etc.

Server side programming has to do with generating dynamic content. It runs on servers. Many of these servers are "headless". Most web pages are not static, they search a database in order to show the user updated personalized information. This sides interacts with the back end, like say, the database.

This programming can be done in a lot of languages:
  • PHP
  • Java and jsp
  • asp
  • Perl
  • Python
  • Ruby on Rails, etc.

This code has to do with:
  • Querying the database
  • Encode the data into html
  • Insert and update information onto the database
  • Business rules and calculations

The person in charge of server side programming must know:
  • some of the languages mentioned above
  • HTML
  • SQL,
  • linux/unix shell scripting
  • OOP
  • business rules, etc.”

3.
Client-Side vs. Server-Side Code: What’s the Difference?
In web applications, there is the client and the server. The “client” is a web browser, like Internet Explorer, Google Chrome,Firefox, etc. The “server” is a web application server at a remote location that will process web requests and send pages to the client. Web applications can contain code that is processed on the client’s browser or on the web server. However, web applications have a disconnected architecture, which means that there is never a live, constant connection between the page displayed in the client’s browser and a web or database server. The majority of the processing will be done at the server and not on the client’s internet browser. When a database needs to be accessed on a server, the web application will post the page back to the web server and server-side code will process the request.

In order to fully understand the web application’s architecture, we must understand postback and the page life cycle, which I have discussed more extensively in previous articles.

Server-Side Code
There are several server-side technologies that can be used when developing web applications. The most popular is Microsoft’s ASP.NET. In ASP.NET, server-side code uses the .NET Framework and is written in languages like C# and VB.NET. Server-side processing is used to interact with permanent storage like databases or files. The server will also render pages to the client and process user input. Server-side processing happens when a page is first requested and when pages are posted back to the server. Examples of server-side processing are user validation, saving and retrieving data, and navigating to other pages.

The disadvantage of server-side processing is the page postback: it can introduce processing overhead that can decrease performance and force the user to wait for the page to be processed and recreated. Once the page is posted back to the server, the client must wait for the server to process the request and send the page back to the client.

Client-Side Code
The benefits of client-side processing in an ASP.NET web application are programming languages like C# and VB.NET along with the .NET Framework. Languages like C# and VB.NET sit on top of the .NET framework and have all the benefits of object oriented architectures like inheritance, implementing interfaces and polymorphism.

In contrast to server-side code, client-side scripts are embedded on the client’s web page and processed on the client’s internet browser. Client-side scripts are written in some type of scripting language like JavaScript and interact directly with the page’s HTML elements like text boxes, buttons, list-boxes and tables. HTML and CSS (cascading style sheets) are also used in the client. In order for client-side code to work, the client’s internet browser must support these languages.

There are many advantages to client-side scripting including faster response times, a more interactive application, and less overhead on the web server. Client-side code is ideal for when the page elements need to be changed without the need to contact the database. A good example would be to dynamically show and hide elements based on user inputs. One of the most common examples is input validation and Microsoft’s Visual Studio includes a set of client-side validation controls.

However, disadvantages of client-side scripting are that scripting languages require more time and effort, while the client’s browser must support that scripting language.

Ajax (Asynchronous JavaScript and XML)
The general rule is to use server-side processing and page postbacks when the client needs to interact with server-side objects like databases, files, etc. However, the concept of Ajax has changed the rules quite a bit. Ajax is the concept of the client calling the server directly to interact with server objects like a database, without a postback involved.

Ajax is a concept that involves a group of existing technologies such as server-side data, web services and client-side scripting. The client-side scripts will call a web service and the web service processes the database request. The request could be the retrieve and/or save data. Ajax calls are asynchronous, meaning that once the client makes an Ajax call to the web service, the client is not locked and waiting for a response. The web service will send a response back to the client when their task has completed. The client will intercept the response and process the response accordingly.

A significant breakthrough in client-side scripting is jQuery. To quote, jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.

Starting with Visual Studio 2005, Microsoft has offered their Ajax Control Toolkit. This a set of ASP.NET controls that have plenty of built-in client-side processing. With Visual Studio 2008, they’ve offered AJAX-enabled WCF Services. These web services are streamlined for asynchronous Ajax callbacks and require little client-side scripting.

In conclusion, the amount of the client-side scripting used in web applications will continue to increase as its power, flexibility and simplicity continue to increase.

4.
Explain the difference between client-side script and server-side script?
“client side script perform on the browser and the server-side script performs on the web server”

“Differences between Client-side and Server-side Scripting Client-side Environment The client-side environment used to run scripts is usually a browser. The processing takes place on the end users computer. The source code is transferred from the web server to the users computer over the internet and run directly in the browser. The scripting language needs to be enabled on the client computer. Sometimes if a user is conscious of security risks they may switch the scripting facility off. When this is the case a message usually pops up to alert the user when script is attempting to run. Server-side Environment The server-side environment that runs a scripting language is a web server. A user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages. This HTML is then sent to the client browser. It is usually used to provide interactive web sites that interface to databases or other data stores on the server. This is different from client-side scripting where scripts are run by the viewing web browser, usually in JavaScript. The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.”

“Client-side script is taking action on the user's (the client's) computer. it is used to provide us functionality without needing access to a web server. Server-side script means that the action takes place on a web server. As to get data from Database and use in show information then need to Server side script.”

No comments:

Post a Comment