Karl
Karl

Reputation: 129

structure for jquery in my mvc project

whats the best way of structure jqueryfiles in my mvc app. Now i have all my scripts in script folder and it starting to be difficult to have a good overview.

//thanks

Upvotes: 1

Views: 1087

Answers (4)

John Munsch
John Munsch

Reputation: 19528

The HTML5 Boilerplate has some minimal structure for JavaScript already. Anything I do will likely be built on top of that because there is at least a chance that another developer will have encountered it prior to hitting it in my project.

Boilerplate has a "js" subdirectory that contains all the JavaScript, another directory under that called "libs" that has just jQuery and Modernizr, and a "mylibs" directory where you're directed to put all the third party libraries (for example, the libraries for jQuery templates or Lawnchair).

js
  libs
  mylibs
  plugins.js
  script.js

They also recommend your short plugins should be concatenated in plugins.js and your basic script stuff go into script.js. Of course, that won't work for a large project, but you've at least got a start with just the js, js/libs, and js/mylibs structure. At the moment I'm using a JavaScript per HTML file with a corresponding name (blahblah.html + blahblah.js) but long term I know I'm going to need more structure than that.

Upvotes: 2

Domenic
Domenic

Reputation: 112827

We used the following structure on my last project:

Scripts
|
|- jQuery
|- Libraries
|- Infrastructure
|- PageSpecific

jQuery contained jQuery and any plugins. Libraries contained other third-party libraries (e.g. underscore.js). Infrastructure contained shared JavaScript modules, e.g. one full of utility functions, or one for handling server-side account-management communications, etc. PageSpecific contained code to wire up event handlers and page-specific logic.

Upvotes: 3

Raj
Raj

Reputation: 22926

It is always a good idea to keep your css files and javascripts organized within your web application.

  • Have two main folders 'styles' and 'scripts' in the root folder of your application.
  • Inside each of these folders, create sub folders that reflect specific module in your app like 'jquery', 'blueprint' etc and place those files over there.

Upvotes: 0

JasCav
JasCav

Reputation: 34632

Keeping your JavaScript files in the Scripts folder is the way to do it. If you want, you can use subfolders within the Scripts folder so that it's a little more organized.

Upvotes: 1

Related Questions