Server & Client

Key Points

In conversation with a friend of mine, I realized that he lacked a firm grasp of the client/server relationship between web browsers, also known as “user agents,” and web servers. The following has been written for him, but I decided to post it here because I believe it may be of interest to others.

First, let your author define a client/server relationship. While there are many different systems in the world that use a client/server relationship, we’ll be considering it solely from the perspective of the web. A server is a computer system that makes resources available to other systems upon receiving a request. A client sends requests to the server, receives replies, and then is able to act on the information it receives.

In the case of the web, the server holds a variety of resources. Typically these are web pages. An individual web page is actually composed of several files: a document, images, videos, stylesheets, and  server-side and client-side scripts. The server assembles all of this into a coherent package of data and then transfer it over to the client, typically a web browser, which displays it the user.

The language the server and the client speak to each other is called HyperText Transport Protocol, HTTP for short. HTTP is a stateless protocol. That means the browser sends a request, the server replies, and then the server closes the connection and completely forgets about the browser. Each exchange is an isolated transaction with no context from previous exchanges.

Along the way, those who designed solutions on the web realized that there was sometimes a very real need for state. Thus a few different solutions, including browser cookies and PHP sessions, were invented to graft state on top of the stateless nature of HTTP. Into all of this come the server-side and client-side scripting technologies which create and rely on that state.

Server-side scripts are executed by the server and modify its response to the client upon receiving a request. They allow developers to create dynamic content (web pages that change based on the information sent by the user).

Client-side scripts, typically written in Javascript, are sent by the server to the browser where they are interpreted. As far as the server is concerned, the Javascript is just another sort of file it pushes down its connection. It doesn’t do any special work or interpretation of the Javascript.

Server-side scripts offer the advantage of security and integration with server-side resources. Because the scripts run on the server, a malicious user can’t simply fake an outcome and send data back to the server to trick it. The server-side scripts can also record information into the server’s database or into a file to store long-term information for the user. Also since the user only sees the output of the server-side script, proprietary code and technology aren’t exposed to clients who could simply copy them or derive their own sites from them.

The downsides of server-side scripts is that they pose a “scalability” challenge because as the server receives more requests, it must tie up more resources processing the server-side scripts and creating dynamic pages to then send over to the browsers. This must all be done quickly because the browser, and therefore user, sit and wait until the scripts complete on the server. If load becomes too high, the server may slow down unacceptably or scripts may even fail to complete successfully. At that point, the server owner must either find significant performance gains in refactoring the scripts or upgrade the server.

Client-side scripting is essentially the opposite. Since all the execution happens in the user’s browser, CPU and memory resources are readily available and a slow down on one user’s browser won’t affect any other clients accessing the server. Because browsers have typically been single-threaded, it’s possible to create scripts that are too intensive and appear to make the browser “hang” while they execute. This will change as the new HTML5 Web Workers technology becomes available on more computers, through users upgrading to more recent browser versions.

The term “Web 2.0” was introduced to build excitement around and express the idea of a more interactive web. This web, which has become increasingly common place, relies on using Javascript to send background requests to server scripts. The Javascript also receives the reply in the background and then updates the page based on the information received. This makes dynamic pages more responsive by not requiring a full page reload every time the browser exchanges some information with the server.

One final note: if you haven’t upgraded your browser in a while, get a better browser. Many web developers are pressured to support old browsers with limited features. As you, the user, adopts newer browsers, we can build better applications, and we can build them faster and more easily. The outcome is a better web for all of us. I’d strongly recommend you try the latest version of Google Chrome.


About Fergus

Fergus likes to invent cool titles for himself, such as “Communications Specialist” or “Internet Architect”. What it really comes down to is that Fergus’s passion is internet communication. He believes that helping people communicate more effectively makes the world a better place. To this end, he seeks opportunities to help individuals, businesses, and non-profits to communicate their ideas, products, and services beautifully. Some examples of the types of work Fergus undertakes: web design, graphic design, programming, and search-engine optimization. Fergus also enjoys consulting with people about their existing web sites and strategies as well as their plans. Fergus doesn’t enjoy writing about himself in the third-person quite as much, but sometimes it seems a necessary evil.
This entry was posted in Programming, Web and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s