RSS

Include Js file using js file

17 Aug

//This function include js files for the application

main.js

function include(file) {

var script  = document.createElement(‘script’);

script.src  = file;

script.type = ‘text/javascript’;

script.defer = true;

document.getElementsByTagName(‘head’).item(0).appendChild(script);

}

include(‘file path/test.js’);

include(‘file path/testimport.js’);

No need to include all the file in the html just include main.js file, main.js code includes test.js and testimport.js in header automatically.

 
Leave a comment

Posted by on August 17, 2011 in Javascript

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: