JQuery LoadOnDemand plugin
Posted by moutaz on December 10th, 2008Sometimes you have many features in the page that needs many javascript/css files to be loaded� , so loading the javascript files each time the page loads doesn’t make sense , so I always prefer to load those files once needed or loading them in the backend where the user experience is not affected by the slowness of the page , and sometimes your site provides theme selection so refreshing the page each time the user selects a different theme also doesn’t make sense .
JQuery� provides a getScript function that loads a javascript files using Ajax Get !! and you can provide a callback function that will be called once the script is loaded successfully .
I have implemented the idea in different way , My plugin can get javascript and css files by loading it as a new element to the header tag .� and can be used as follow:
<script type="javascript"> <!-- $.loadScriptCSS("getJSValidators.js" , "javascript", "isValidName" , "CheckForm"); //--> </script>
1st argument� : the url of the file
2nd argument :the type ( javascript , css)
3rd argument : a function name exists in the js file that will be used by the plugin to check if the js file is loaded or not
4th argument :the callback funciton to be called once the js file is loaded correctly
Enjoy jquery-loadondemand
Recent Comments