AJAX-Tips Tutorials
AJAX-TipsEfficient JavaScript Loading Technique
An important feature of an Ajax or JavaScript based application is its ability to load in various browsers. Ajax and JavaScript based applications are often regarded as resources hogs since they require processing power not only in terms of bandwidth but also from local computers.
As the online Ajax and JavaScript based applications become more complicated, more processing power is required from users. If the user does not have the required configuration such as bandwidth speed, the application may not work as expected.
But efficient loading is not necessarily a problem for users. Developers have to improve their application so that their application will load well even though the user does not have the ideal bandwidth or gadget. Developers have to create some "tricks" to improve the loading time of their application.
Two JavaScript File Technique
There is a technique proposed by a developer that might improve the loading time of the Ajax based application. Steve Souders proposed in creating two separate JavaScript files that will load in the browser. The first file will be dedicated to load the essential JavaScript codes.
The second file will contain the files that will provide the initial interaction with users. The first file will have the <script> tag which will be used to call the functions in the interactive JavaScript file. The <script> should be placed in the bottom inside the <body> script.
Advantages of the Technique
Using two JavaScript files to improve loading time of Ajax and JavaScript application is very unique but will work under the right conditions. Using two connecting JavaScript files will ease browser loading.
The browser can deal with the essential scripts first before reading the non-essential files but still important for users. The browser will be prevented from reading and processing the non-essential functions but will speed up the processing time for both files.
Another advantage is the customization of experience for developers. By using two JavaScript files, the developers can ensure that the first functions will be read. The files will separate the functions deemed required by the developers in properly loading the application.
Disadvantage
Like many load optimization techniques, there are some disadvantages a developer might experience when using this function. As already indicated, this technique will work in perfect conditions. That means your JavaScript file should be local with functions that will be loaded from the server. Using functions that call on external files may not work well in this scenario.
Since the function will connect to the second file, the function might take a while before the external function can be called. External functions using (even those in HTML) will not load as expected since the first JavaScript file is already connecting to another file. This is already considered as an external connection and an additional connection might not work well with browsers.
Using two JavaScript files is a unique but effective method in improving JavaScript loading. While it can't be used in calling external functions, it is a good option for simple Ajax and JavaScript based application.
Sponsored Links
