Week 4 - Client and Server Side Scripting

Welcome to week 4, Where we will introduce the concepts of Client-Side Scripting versus Server Side Scripting and talk about the technologies involved, and the misconceptions that new developers have over these concepts.

Setting up VS Code for PHP

The instructions for setting up VSCode to work with PHP are here.

Scripting Versus Compiled Programs

Every program is a made up of set of instructions called an algorithm, whether it is to add two numbers or request information over the internet. Compilers and interpreters both take human-readable code, in many different languages, and converts it to machine language code.

Compiled ProgramsCompiled Programs

In a compiled program, a developer writes the code, compiles it into a form of an executable program, which then runs on a computer or other device. Programs like Microsoft Word, Visual Studio Code, Notepad, and Google are compiled programs that you execute and run on demand. The main functions of the program are not real-time, but preset to follow specific routines.

Most of the time this results in a .exe or .obj file that is executed on the destination machine. Most of the time these programs are installed on a workstation and executed on demand, but the conversion to machine language was done long ago, during compiling.

Scripting Programs - Interpreted

Scripted programs are code that is also converted to machine language, but it is done by an interpreter in real-time. Meaning that there is no pre-compile process and the code is interpreted on the fly. This makes interpreted code much more flexible to adjust based on the current situation, user input, or most commonly, varying data being retrieved from a database.

When we obtain database information, we often do not have an idea of how many rows we will get, what is in the data, or even sometimes how many columns we will receive. Scripting languages allow us to take this information, and display it in real-time to a browser

Some of the most common use of scripting languages are:

Some of this scripting is run on a server, and some is run on the client.

Client versus Server for Websites

Most of the Internet is based on a 3-tier architecture:

Before we go to far, let us define the difference between the server and the client.

ServerServer Centre

The server is the hosting location of the Website. They are high-powered computers running web server application (Apache or IIS are the big ones). The server is typically behind secure firewalls and has secure contact with a database. All of this must be protected from the public and is typically a 3rd party hosting provider such as GoDaddy, Host.com, Heroku, etc.

Servers will receive requests from a client, process the request, and respond with the requested information. Servers can be configured to run different web applications/technologies running several different popular/powerful scripting technologies (PHP, JSP, ASP to name a few)

Client

The client is a simple concept that is often misconceived. The client machine is nothing more that the users computer. When users browse the web, they are working on a client machine, which is where the browser is running, and through the URL are connecting to a server which feeds the client the content they see, but it is the client machine which displays the output.

The client is also know as the Local Machine running a web browser (IE, Netscape, Safari, Mozilla, Chrome, FireFox, Edge, Opera…)

Client-Side ScriptingJavaScript Logo

Client-Side scripting runs in the browser (NOT on the server), on the client machine entirely secluded from the server. More specifically, the browser is an interpreter that interprets the code and executes it as required. This means that the code does not take server resources, but the resources of only the workstation (client machine) the user is currently sitting at. This distributed use of computers takes an enormous workload off of the server.

Client-side scripting is often used to:

Most of the time, client-side scripting is written in JavaScript, but can also be created in VB Script (Visual Basic), or in JQuery. HTML is a mark-up language, but is still interpreted by the browser on the client-side as well, so it is also technically a scripting language.

Server-Side ScriptingPHP LogoCS Logo

Server-Side scripting is still interpreted code, but it is interpreted on the server in real-time, it is not compiled. The large difference between interpreting code on the server versus the client, is the ability to securely communicate with other servers, such as a database server, or to use the scripts to generate other scripts to send to the client. That is, the server-side script can write HTML code dynamically that is sent to the client browser the same as static HTML.

Server-side script can be written in many different languages and all can run equally as well, but they all have the same trait in common, they generate client scripts, or HTML, to send to the browser.

Some examples of Server-Side scripting languages are: