Best practices for maintaining javascript libraries in repositories?

1.3k Views Asked by At

When developing javascript code, what are the best practices for maintaining the code in repositories?

For example, suppose I develop a set of useful functions and put them in a script called "sugar.js". In the code repository I put them in c:/codebase/suger.js.

Now I want to use the script in a web site being developed and I locate it at c:\mywebsite\sugar.js (ready for uploading to a server)

Do I keep a copy of sugar.js? What if I fix sugar.js in one location - it won't be synchronized with the other?

What if I build a second web site that also uses sugar.js? Do I take another copy located at, say, c:\mywebsite2\sugar.js?

1

There are 1 best solutions below

0
Alex Moore On

If you are using something like visual studio, you can use NuGet for versioning many of the popular javascript frameworks on a per-project basis.

If you are writing in something else, you could try package managers such as npmjs or http://jspkg.com/JSPkg.

If it is your own library, I would recommend setting up source control and having versioned releases as branches or tags, that way you can keep track of everything. Git and GitHub support this type of thing, and you can set it up to have each version as a zipped download.

I would also try to keep each project's javascript files separate, that way any changes won't immediately break every site, just the one you recently updated. This advice could go out the window if you are running hundreds of sites and really just need a CDN.