views:

178

answers:

1

Assuming a person has Visual Studio 2008 set up correctly for JavaScript Intellisense, what are the best practices for the actual javascript reference declarations?

The basic form, of course, is (right up at the top of the file):

///<reference path="path-to-file.js" />

But what are the rules for the path?

Webapps

Should web applications use forward slashes like a url? "filename.js" for files in the same directory? "./filename.js"? Root relative "/path/to/filename.js"? Are all of these supposed to work? Do relative paths like "../../filename.js" work?

Class Libraries

What about when building class libraries of embedded resource .js files? Should these use backslashes like a Windows file path? Escaped double backslashes like in a .NET string literal?

What about when a .js file in a webapp references one in a class library? This could commonly be the case during development of a plugin - you have a set of existing plugins, and you develop a new one in a web context so you don't have to keep rebuilding the class library, and then when you're done you move it into the class library. How would you reference that? By full "C:\long\path\to\project\directory\file.js"?

Cascading Dependencies

What about if A.js references B.js which references C.js which references D.js, all from different directories?

Should A.js contain references to B, C, and D, or should the references cascade to A.js?

More??

I'll enable the Community Wiki so that hopefully this can become a compendium of best practices.