Unobtrusive JavascriptUnobtrusive Javascript is the use of scripting to add functionality to the site without compromising the experience for visitors who do not have Javascript available or enabled. Javascript should be used to enhance the functionality of a web site. These enhancements should provide a much more interactive experience rather than be required in order to view the site's content. This process is known as Progressive Enhancement. Unobtrusive scripting means that all the scripts are kept in separate files making them easier to maintain. For example if a function is improved, then you would only need to change the the one file that contained this function and the effects will be seen on every page that contains this script. Keeping the Javascript separate also means that the it can be worked on at the same time as somebody else is working on the HTML files. The use of unobtrusive scripting means that when a user visits a page, all the separate Javascript files are downloaded and then kept in the computer's cache memory. This means that they will not have to be downloaded on subsequent visits. This will speed up download time for users and also take some pressure off your own server. As well as users without Javascript enabled devices some browsers will have versions of Javascript installed that only provided limited functionality. It is possible to use Javascript to detect which browser is being used ('browser sniffing'), although this involves lots of code and would have to be constantly updated as new browsers are released. Object detection instead is a better solution that tests to see if the browser understands a method, before using it. If it doesn't, then the script stops running and displays the normal page without the Javascript enhancement.
|