Arrange JavaScript files for a project [duplicate]

3

I'm working on a Web System with multiple screens and they have different functions in Javascript and several apply to only one page. How do I organize Javascript files? What is the best practice?

  • Create a file for each page
  • Create a full-featured file
  • Another way?
asked by anonymous 19.08.2015 / 22:52

1 answer

2

The organization of your files depends on the type of the project, size, existing modules, etc ... Try to identify if your javascripts functions can be grouped in different files, for example:

In a project you have:

  • Utility functions for string, date, and numbers.
  • Data validation functions
  • Processing functions

Here your structure may look like:

< your project < js < utils < stringUtils.js < numberUtils.js < dateUtils.js < validation < js < js < process < js < .... js

Thus, we group our files into different files and into different directories. The project was well divided and intuitive. It's just an example of organization for you to get an idea of how to build your structure.

EDIT: Managers

Depending on the structure of your project, you may want to use file managers to make your work easier. On some projects where I use AngularJS , I usually use RequireJS . RequireJS manages all dependencies on .js files by importing them when necessary.

Read about it here . This link also talks about optimization .

    
19.08.2015 / 23:06