Derg
Derg

Reputation: 301

packaging multiple javascript files

I am developing a javascript library made up of a few tightly coupled classes. The classes are broken up into individual .js files, but for brevity's sake, I envision the end user including a single .js file encompassing the entire implementation.

My question is, what is the ideal method for distributing the API? Should I simply repackage all the code into a single .js file, should I keep the existing file structure and setup a series of

document.write('<script src="file1.js"><\/script>');

commands into a 'primary' script file, or is there another way that makes more sense?

Thanks!

Upvotes: 1

Views: 1190

Answers (2)

kinakuta
kinakuta

Reputation: 9037

For performance and maintenance reasons, I believe it's better to package them into a single file. The fewer http requests made to retrieve scripts, the better performance (in general - very long scripts can also cause performance slowdown.) I'd also recommend namespacing your api.

Upvotes: 0

Ryan Doom
Ryan Doom

Reputation: 2391

I think if you don't intend for the user to jump in there and need to modify it and it's tightly coupled like you mentioned you should put it all in a single JS file and then minify it.

You can provide an unminified version as well but seems for their simplicity you should put it all in a single JS file.

Upvotes: 2

Related Questions