javascript “include” strategies

Duplicate of: http://stackoverflow.com/questions/203113/use-javascript-to-inject-script-references-as-needed

Javascript doesn't have any directive to "include" or "import" another js file. This means that if script1.js uses functions/objects defined in script2.js, then every html page that includes script1.js must include script2.js before it.

This shouldn't be a big problem if you only have 2 js files in like 10 html pages. I mean, it's manageable then!

But say suddenly you change script1.js and improve it by using functions/objects defined in a new file, script3.js The problem is, you can't just tell script1.js to include script3.js, instead, you have to remember every html file that included script1.js and update it to include script3.js as well!

This seems like rather stupid way of organizing code.

Are there recommended strategies or practices to deal with this issue?

Would it be acceptable to have a gigantic js file that holds all the functionality that you use across the website?

Answers


Use dynamic includes:

http://stackoverflow.com/questions/203113/use-javascript-to-inject-script-references-as-needed


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.