|
Modern websites are becoming more and more similar to applications that are not inferior to independent applications in functionality. Do you want your site to be as interactive and functional as a full-fledged application? Then you should make use of one of web development technologies while developing your web project. The program codes that realize these technologies (in other words, scripts) split into two main groups: sever-side scripts and client-side scripts. Servers-side scripts are executed by the server in response to requests sent by the client application (in this case – by the browser). Client-side scripts, correspondingly, are executed by the client application itself.
Let us take a closer look at client-side scripts. Why do web developers use them so often?
The notion of client-side scripts
You might already know that web pages are mostly written in the hypertext markup language – HTML. However, this language is responsible for the presentation (design) of web pages, and it is impossible to perform any dynamic action using this language. It is client-side scripts that help to make web pages dynamic. Client-side scripts are a special type of scripts that give an opportunity to change the content of an HTML page without having to re-load the page from the server. Quite often client-side scripts are embedded within the HTML code of a web page, and the user does not have to download and install any additional software that will execute client-side scripts. All the user needs is a web browser that supports client-side scripts. All modern web browsers (except some old versions) support execution of the most widespread client-side scripts.
The most widespread programming languages used for writing client-side scripts include JavaScript, VBScript, and ActionScript which is used in Flash and SilverLight technologies. Let us take a closer look at the JavaScript and VBScript programming languages as they are the brightest examples of client-side scripting languages.
JavaScript
JavaScript is one of the most popular client-side scripting languages used for web development. JavaScript was developed in early 1990-s by Brendan Eich of Netscape. It was initially developed for interaction with Netscape Navigator web browser only, and it was first deployed in beta versions of Netscape Navigator 2.0. However, today this web programming language is very widespread and is supported by practically all web browsers. Moreover, scripts written in the JavaScript programming language are supported by such software applications as Adobe Photoshop, Adobe Dreamweaver, Adobe Illustrator or Adobe InDesign that are actively used by professionals for web design development.
Why is JavaScript so widespread and popular?
The brightest example of JavaScript use is filling-in of the registration forms. A client-side script check the information in the form before it is send to the server and shows mistakes if there are any. The rest of information is saved in the dynamic memory, and there is no need to fill in all fields of the registration form once more if you have made a mistake. JavaScript can also perform a lot of other tasks that cannot be performed by static HTML pages. For example, client-side scripts written in JavaScript can change the page content in response to user actions, create tooltips, make the page respond to mouse clicks and cursor movements etc.
How to add JavaScript on a web page?
There are two main ways. The first way has already been mentioned above – a JavaScript program code may be embedded within an HTML document. The code is usually inserted withing the tag, because in this case the script is loaded simultaneously with the whole page. The script is inserted with the help of the following code:
<script type="text/javascript">
JavaScript code
</script>
The second way is to write the required client-side script in a separate file and save is with the .js extension. This file will be referenced by the document that will use the client-side script. It is done in the following way:
<script src="/file_name.js">
</script>
VBScript
Visual Basic Scripting Edition, also known as VBS, was developed by Microsoft. It is a worthy competitor to the popular JavaScript language. VBScript is modeled on Visual Basic, therefore its syntax and structure are similar to the rest of programming languages modeled on Visual Basic. However, VBScript is not so difficult and has only one type of variables – variant. Thanks to a big number of already written user scripts, as well as its simplicity and accessibility VBScript is becoming more and more popular. However, it is supported by Internet Explorer (web browser developed by Microsoft) only. The rest of the browsers need special extensions (plugins) designed for execution of client-side scripts written in VBScript. Scripts written in VBScript allow to perform the same range of tasks as scripts written in JavaScript, therefore we will not tell about it once more.
To insert VBScript code into the source code of the page you should use a construction that slightly differs from that used for scripts written in JavaScript:
<script language="vbscript">
VBScript code
</script>
Pros and cons of client-side scripts
JavaScript and VBScript are the object of heated debates between web developers. Some of them think that JavaScript works faster than VBScript, but they admit that the latter one has wider functional. Anyway, both of these languages have several common advantages:
- the data are not sent to the server, therefore web applications work much quicker;
- the users do not have to install additional software for execution of client-side scripts;
- hosting providers do not take money for using client-side scripting languages;
- there is an opportunity to change the style and content of web pages dynamically depending on the client's browser;
- the pages can be updated automatically after a certain period of time;
- the pages can respond to user actions (mouse cursor movement, mouse button clicks);
- client-side scripts allow to perform various mathematical calculations.
Unfortunately, every medal has its reverse: client-side scripts also have certain disadvantages.
To see the source code of a script it is enough just to view the source code of the web page – almost every web browser has such an option. Therefore if you try to protect certain data with a password using a client-side script, you will fail – everyone will be able to view the source code of the page and learn all passwords. Sometimes users disable the support of client-side scripts in their browsers; it means, that in this case the scripts will not be executed.
By the way, it is worth mentioning that both JavaScript and VBScript are used for writing not only client-side, but also sever-side scripts, but they have no opportunity to send a file to the server. Therefore to solve tasks related to sending data to the server you'd better use server-side scripting languages.
TAGS
client-side scripts,
scripts,
web development,
vbscript,
javascript,
website development,
scripting |