Saturday 2 May 2015

M2: How a Scripting Language can Improve the Functionality of a Website

Introduction

In this document I will be comparing the server side and client side scripting that takes place in websites when you're using a web browser. I will explain the positives and drawbacks of each and what they are generally used for and their purpose.

Client Side Scripting over Server Side Scripting

Client side scripting is when a scripting language runs its functionality on the user's PC through their web browser rather than the server running the website. Server side scripting happens where the website is hosted directly on the server, the opposite of client side scripting. People who host web servers tend to run the most demanding scripts on the client’s PC, this is due to the fact that the client’s PC is a much faster system. Since servers are designed to just run a huge amount of data on the internet, and if you’re using a shared server design, running scripts on the user’s PC is a huge advantage.
Client side and server side scripting have different scripting environments which they run on, obviously client side scripting is ran on the web browser itself and works with the HTML code. While server side scripting is designed to run on a web server environment, and might even use a whole different scripting language altogether.
Client side has a few advantages over server side scripting, especially for the goal of making interactive web pages and interactive gadgets or applets. First the system that client side scripting will be running on is most of the time going to be a lot faster than the server. This means any client side scripting will run significantly faster than server side scripting and allows for fast web page loading. It also means the interactivity will not be hindered, as for server side scripting, it might actually slowdown interactive elements of the web page.
Server side scripting is mostly used for communicating with databases and retrieving information on the user. Things like e-commerce, social networks, security, privacy and data keeping will be used for server side scripting, as servers can handle huge amounts of data. Which is where client side scripting can fall short, but since interactivity and web page presentation does not depend on huge amounts of data, it does not need that sort of power.
Client side scripting is a lot more advantageous to use against server side scripting for interactivity of web pages. Simply due to the fact that the computer running the said script will be faster, which also in turn relieves a huge amount of stress on the server side scripting. Which means it allows for the server side scripting to deal with more specific situations to do with databases and security.

User Experience and Client Side Scripting

Client side scripting is a huge advantage for basic user experience and interaction with the web page, it is extremely useful since it is used mainly for interaction and the design of the web page. User experience in this day and age depends heavily on the usage of client side scripting, things like drop-down boxes would not be even possible without the usage of client side scripting.
Before scripting, things were extremely basic as web sites only used HTML and CSS, there weren’t any forms or animations of any sort, nor were there any drop-down boxes. Client side scripting is extremely important because it saves the user time, and makes your web page easier to navigate, and provides visual benefits in making your design more appealing and understandable. For example, imagine a website like Amazon, without drop-down boxes:


As you can see, I am hovering my mouse over “Shop by Department” that then shows a drop down box which contains a comprehensive lists of all the different Amazon shopping departments I can search in. If there was no client-side scripting, this would either load extremely slowly, or would not exist at all. Since server side scripting is so slow, it would be more beneficial to have this has a button that redirected you to a list of different departments if client side scripting did not exist.
We take for granted our experience viewing web pages and how helpful a client side scripting language like a JavaScript aids in the usability of web pages. It’s not only drop down boxes this would effect either, if you didn’t have client side scripting, you would not have animated buttons, lists, effects, etc. When JavaScript did not take off, a lot of interaction  was based around Flash Player by Adobe, but this wasn’t fast or efficient in making your website fully animated. It could slow down the whole website for people who did not have fast PCs to run all of the Flash content, so when JavaScript and client side scripting became an attractive and useful tool to take advantage of. Websites restructured themselves according to the use of client side scripting, and has now allowed all of these increased user experiences.
Even YouTube used to use Flash Player, and now uses WEBM files to run animated videos, which takes advantage of client side scripting. The usage of this has also made it possible to watch videos in sixty frames per second, and up to 4K resolutions, making the user experience of watching videos in the world wide web much more enjoyable and hassle free.



In fact YouTube is a good example of presenting how client side scripting has aided user experience and the usability of browsing the web. As you can see in the navigation bar for watching videos, there are three buttons representing “What to Watch”, “My Subscriptions” and “Music”. Switching between these is almost seamless, and it actually loads within the web site itself, rather than your web browser. Due to pre-loaded client side scripting, if YouTube did not have client side scripting it probably would not load new pages within itself and depend much more on the web browser. So like an ordinary website it would probably redirect you to a different web page stored within a database.

Form Validation and Client Side Scripting

Client side scripting also forwarded the increase in security on the World Wide Web and has provided a huge array of benefits for the user. Form validation refers to forms returning messages based on what the user has inputted into the form’s text boxes, the form information can even be compared to a database.
However simple things like checking if a form has actually been filled out or not can be done on a client side scripting language like JavaScript. A function like this can be created:
function validateForm() {
    
var x = document.forms["myForm"]["fname"].value;
    
if (x == null || x == "") {
        alert(
"Name must be filled out");
        
return false;
    }
}
Checking for an empty form space is a lot faster than checking if the correct information has been entered because in this function everything is done on the client side. While correct information has to be compared with a server’s database, or a database linked to the web server the user is currently using to view the web site.
Client side scripting is able improve form validation firstly in the sense that it will contain the same theme and feel of other client scripting aspects used within the web page. There will most likely be some aspects that use client side scripting, and since the form validation will also be using client side scripting, you can combine these aspects. You could create drop-down select boxes within the forms, and also make it so it sends and error message if they chose to ignore the drop-down select box.
Client side scripting also makes form validation a lot more secure, scripting languages like JavaScript were designed with security in mind, and it’s extremely difficult to track information being sent through client side scripting. If you were to use HTML based form validation, it would be significantly easier for malicious users to retrieve information if they were to already get past the first layers of security the website most likely has implemented.
Client side scripting can also work with server side scripting, which can improve form validation by a great amount in terms of accurate and valid information. Client side scripting can work with server side scripting and base information entered from the client sides form with a server side form, it can also be compared to the database also. It’s the reason it can sometimes take a long time for you to log in or to create a new account.

Conclusion:

In conclusion, client side scripting has improved the user accessibility of the web, and has enabled people to have a better understanding of the web pages they view. It has made web pages evolve in the way they look, the way they function and the way they handle information from a data base. It has also improved the loading speeds of web pages tremendously over the course of the evolution of client side scripting. Client side scripting and Server side scripting are both required for a functioning website, but for interactivity and form validation, client side scripting is imperative.

Sources:

http://www.w3schools.com/js/js_validation.asp, 02/05/2015, used in page 4 for source code and form validation.
https://www.youtube.com/, 02/05/2015, used in page 3 for image of the YouTube website.
http://www.amazon.co.uk/ , 02/05/2015, used in page 2 for image of the Amazon website.
http://www.yourwebskills.com/clientserver.php, used in page 1 for information gathered.


Friday 1 May 2015

P3 JavaScript and JQuery

Introduction:

In this document I will be describing the language JavaScript, its purpose, how it functions, why it was created and its implementation with HTML and CSS. I will also describe the complementary library known as JQuery, which is one of the biggest and most used JavaScript libraries.

JavaScript:

JavaScript is a scripting language used for web development and web production, JavaScript was created in order to add interactivity to websites. An example of the interactivity it wanted to achieve are things like drop-down boxes, animated tabs, etc. Things commonly found in software applications like Microsoft Office and the web browser Google Chrome itself. Below is an image of a typical student-based website known as Moodle; which is used for our studies and includes a database of resources and course information. JavaScript allows that drop-down box seen in the image to work, since with CSS this would not be at all possible. JavaScript has now become so well known that almost all websites and browsers use JavaScript to run

Javascript is not a programming language and is not able to do complex algorithms and calculations and is mostly used for displaying interactive shapes and forms. JavaScript has been around for a long time and within that time there has been a lot of libraries created to make coding in JavaScript easier the most famous and most used of which is JQuery.
It is now the most accepted principle that websites should use JavaScript or they are not considered professional in any respect. If web developers want to get work, they will have to implement all three languages (HTML, CSS and JavaScript) in their websites. Javascript was created to standardize web development and to work with web developers to create a globalized standard of how web pages should look and how they should work. It was also advanced in 2005 with the community effort of Jesse James Garrett and others to make it so that data can be loaded in the background, which meant avoiding the need of fill page reloads.
JavaScript is now a global standard, mostly for the usefulness of its joint server-side and client-side possibilities, which can relieve stress off the server and run scripts on the client’s computer. Which intern makes webpages load faster, and webpages a lot more efficient.

JQuery

JQuery is a library of JavaScript code that is used to shorten the amount of time to code in JavaScript. It is literally just a text file filled to the brim with different JavaScript functions and code, instead of typing up the lengthy amount of code to open up a drop down box you can just call a function from JQuery. The reason this was created was to improve web-development times.
<head>
  <meta charset="utf-8">
  <title>jQuery UI Accordion - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#accordion" ).accordion();
  });
  </script>
</head>
The code to create this function is worth a few pages and is a lot more difficult to write than to just call the function that is already in the JQuery library. As you can see from the source code below you can save a huge amount of space when using JQuery, and to make your own code a lot neater. It’s also a lot easier and saves a lot of time in development.


var accordion = $.widget( "ui.accordion", {
          version: "1.11.4",
          options: {
                   active: 0,
                   animate: {},
                   collapsible: false,
                   event: "click",
                   header: "> li > :first-child,> :not(li):even",
                   heightStyle: "auto",
                   icons: {
                             activeHeader: "ui-icon-triangle-1-s",
                             header: "ui-icon-triangle-1-e"
                   },

                   // callbacks
                   activate: null,
                   beforeActivate: null
          },

          hideProps: {
                   borderTopWidth: "hide",
                   borderBottomWidth: "hide",
                   paddingTop: "hide",
                   paddingBottom: "hide",
                   height: "hide"
          },

          showProps: {
                   borderTopWidth: "show",
                   borderBottomWidth: "show",
                   paddingTop: "show",
                   paddingBottom: "show",
                   height: "show"
          },

          _create: function() {
                   var options = this.options;
                   this.prevShow = this.prevHide = $();
                   this.element.addClass( "ui-accordion ui-widget ui-helper-reset" )
                             // ARIA
                             .attr( "role", "tablist" );

                   // don't allow collapsible: false and active: false / null
                   if ( !options.collapsible && (options.active === false || options.active == null) ) {
                             options.active = 0;
                   }

                   this._processPanels();
                   // handle negative values
                   if ( options.active < 0 ) {
                             options.active += this.headers.length;
                   }
                   this._refresh();
          },


Sources:

https://jqueryui.com, 01/05/2015, used in page 2 for the source code.

https://www.w3.org/community/webed/wiki/A_Short_History_of_JavaScript, 01/05/2015, used in page 1 for describing the reason JavaScript was created.