Home     |      Learn AJAX     |      Forum     |      Register     |      Submit Resource     |      Submit Article      |      Contact Us

Home AJAX-Tips
 

Ensuring Performance in Script Loading

 

One of the ways of ensuring a well performing Ajax based application is to build an application with an optimized script loading. The beauty of Ajax as an open source is that a single function could be done in so many ways that every developer has a free hand on how to implement things in their application.


However, this is also the bane of Ajax as almost anyone could find a whole on the coding that they become open for different type of attacks. But aside from security, they have to ensure that the application will work as planned.


The trouble with script loading is often based on the fact that it has too many blockages could be done that the application will not work as optimized as possible. The reason for these blockages is security and ensuring the application would cover every data before they are asynchronously streamed to the user.


If the developer wants to remove those blockages, a good option would be to use XHR for proper script loading. But that solution will only open up a lot of security problems that it is just not worth it.


Another reason for the slow script loading is the combination of external scripts and inline scripts. If they are not properly loaded, the inline scripts will have trouble executing the function since they would have to wait for the external scripts first.


But there are actually ways on how to handle script loading without opening up security concerns. Inline script and the external scripts will be coupled, the application should run faster.


Options for Script Loading

There are three options for optimized script loading – the use of onload, onreadystatechange and hardcoded callback. These options are feasible on certain scenarios so that developers will have a wide variety of solutions on how to build the application.


The Onload Option – This is probably the easiest way on how to tie inline scripts. Instead of letting the inline scripts become standalone, connect it with onload so that it could be integrated or coupled with external scripts faster.


The disadvantage of this technique is also on its simplicity. Since you just placed the inline scripts on the onload function, there is no way on telling the inline scripts to work faster.


OnReadyStateChange Command – A lot more complicated to the onload option, this solution for inline scripts will require developers to tie the inline commands not only on onload but also on OnReadyStateChange.


By adding the OnReadyStateChange, developers can actually add commands on when the inline script should start executing. However, this will require a lot more coding and could be confusing if you do not lay out the coding properly.


Better Callback – This option is highly recommended if you think the inline scripting is already ok. Instead of changing the inline scripts make some changes on the external functions instead.


By making some changes on the external scripts, you can specify when the external scripts will get executed. Of course, this comes with the prerequisite that you make the external scripts yourself.



Read Next: Server Side Ajax



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links