My specialised fields are SEO, web design and content writing on a variety of subjects. Online marketing is my arena and learning is my foray . My other interests include interent research, forum participation, reading and travelling.
Meet JavaScript - a scripting language parallel to AppleScript, VBScript and Unix's shell scripting languages, designed by Netscape to be used in tandem with HTML (and XHTML) to deliver more dynamic web pages. Although analogous to full-fledged programming languages such as C, C++ and Java, JavaScript does not call for the understanding of the underlying structure of the program - thus constrained in a manner, yet functional and widely used.
Meet JavaScript - a scripting language parallel to AppleScript, VBScript and Unix's shell scripting languages, designed by Netscape to be used in tandem with HTML (and XHTML) to deliver more dynamic web pages. Although analogous to full-fledged programming languages such as C, C++ and Java, JavaScript does not call for the understanding of the underlying structure of the program - thus constrained in a manner, yet functional and widely used.
Being an interpreted language, which is usually executed over a network connection, JavaScript is slower as compared to compiled languages (such as C). While most scripts are so small and fast that speed degradation is negligibly noticeable by users, longer and more complex scripts need a keen eye for optimization to improve speed factor.
The execution speed of the web pages is vital for the commercial success of any website on Internet. Barely having a quality-based and high-ranking website over Internet cannot yield better revenue. The website should be able to hold the visitor. Authentic studies indicate that the attention span of a regular user is not more than 5 seconds while waiting for a web page to download. This clearly means that low execution speed is equivalent to precious prospective customers lost.
Moving from global changes to local manipulations across your website, you can bring about a remarkable difference in the execution time of your dynamic Web Pages empowered by JavaScript.
Algorithms and Data Structures: Paying attention to the algorithms and data structures is the first step in the direction as these predominantly determine the overall performance of our codes. Using built-in functions to custom replacements is always advisable as these are generally faster. Measuring changes for critical inner loops with respect to different browsers also helps in controlling the performance.
Refactoring: The next step in the process is refactoring or restructuring the code into a more disciplined, simpler and more efficient version. Refactoring basically implies writing a correct, operative and well-commented code, debugging the code and replacing the complex sections with shorter and more efficient ones. For example, caching the frequently used objects and properties and avoiding usage of nested properties reduce the complexity of the code.
Reduce DOM interaction and I/O operations: Minimizing DOM (Document Object Model) interaction and I/O or HTTP requests is another effective means to the end in close succession. Interaction with DOM implicates the time taken by JavaScript interpreter in referencing a scoped object within the code. As JavaScript manipulates web pages through a relatively sluggish DOM, it is wiser to minimize the scope chain of objects to maximize the object resolution speed. Also a window object is faster to full reference. Further, using object literals like car."Toyota" saves space and unnecessary DOM references, as compared to car.make="Honda".
Local Optimizations: Using local optimizations should be saved as the last resort upon global manipulations fetching no speed relief. Local optimization involves measures such as, caching frequently used values, fine-tuning loops and expression to speed up the hot spots, augmenting objects to store additional data, augmenting data structures, hoisting loop-invariant code, flipping and reversing, and unrolling loops with an optimized Duff's Device.
Avoid optimization if at all evitable. But if required, JavaScript coding must be optimized from a global scale to local levels. Each step forward should be taken only if absolutely essential, as the desired results in terms of execution speed are not achieved.