Scripting concept in JavaScript

What is a script?

  • Script is a small, embedded program.
  • The most popular scripting languages on the web are, JavaScript or VBScript.
  • HTML does not have scripting capability, you need to use <script> tag.
  • The <script> tag is used to generate a script.
  • The </script> tag indicates the end of the script or program.

Example : Type attribute

<script type = “text/javascript”>
     document.write(“TutorialRide”);
</script>

The 'type' attribute indicates which script language you are using with the type attribute.

Example : Language attribute

<script language= “javascript”>
     document.write(“TutorialRide”);
</script>

You can also specify the <script language> using the 'language' attribute.

Types of Scripts

1. Client-Side Scripting
2. Server-Side Scripting

1. Client-Side Scripting
  • Client-Side Scripting is an important part of the Dynamic HTML (DHTML).
  • JavaScript is the main client-side scripting language for the web.
  • The scripts are interpreted by the browser.
  • Client-Side scripting is used to make changes in the web page after they arrive at the browser.
  • It is useful for making the pages a bit more interesting and user-friendly.
  • It provides useful gadgets such as calculators, clocks etc.
  • It enables interaction within a web page.
  • It is affected by the processing speed of the user's computer.
Operation of Client-Side Scripting
client side scripting
In the above diagram,
  • The user requests a web page from the server.
  • The server finds the page and sends it to the user.
  • The page is displayed on the browser with any scripts running during or after the display.
  • Client-Side scripting is used to make web page changes after they arrive at the browser.
  • These scripts rely on the user's computer. If the computer is slow, then they may run slow.
  • These scripts may not run at all if the browser does not understand the scripting language.
2. Server-Side Scripting
  • Server-Side Scripting is used in web development.
  • The server-side environment runs a scripting language which is called a web server.
  • Server-Side Scripting is used to provide interactive web sites.
  • It is different from Client-Side Scripting where the scripts are run by viewing the web browser, usually in JavaScript.
  • It is used for allowing the users to have individual accounts and providing data from databases.
  • It allows a level of privacy, personalization and provision of information that is very useful.
  • It includes ASP.NET and PHP.
  • It does not rely on the user having specific browser or plug-in.
  • It is affected by the processing speed of the host server.
Operation of Server-Side Scripting
server side scripting
In the above diagram,
  • The client requests a web page from the server.
  • The script in the page is interpreted by the server, creating or changing the page content to suit the user (client) and the passing data around.
  • The page in its final form is sent to the user(client) and then cannot be changed using Server-Side Scripting.
  • Server-Side Scripting tends to be used for allowing the users to have individual accounts and provides data from the databases.
  • These scripts are never seen by the user.
  • Server-Side script runs on the server and generate results which are sent to the user.
  • Running all the scripts puts a lot of load onto a server but not on the user's system.