My application is using Angularjs at client side and Nodejs at server side to build Single Page Application. Application has many views and complex therefore I have many client side directives and views. Following are my list of client side Angularjs files
1. App.js >> Defining the Angularjs app
2. ApplicationController.js >> This is global controller to handle the common stuff
3. ControllerView1.js, ControllerView2.js, ControllerView3.js, ControllerView4.js, ControllerView5.js, ControllerView6.js, ControllerView7.js, ControllerView8.js and many more
4. Directive1.js, Directive2.js, Directive3.js, Directive4.js, Directive5.js, Directive6.js, Directive7.js, Directive8.js, Directive9.js and many more
Currently I have loaded all these scripts in section as below
<script type="text/javascript" src="/js/vendor/angularjs/angular.min.js"></script>
<script type="text/javascript" src="/js/vendor/angularjs/angular-resource.min.js"></script>
<script type="text/javascript" src="/js/vendor/angularjs/angular-route.min.js"></script>
<script type="text/javascript" src="/js/vendor/angularjs/angular-sanitize.min.js"></script>
<script type="text/javascript" src="/js/vendor/angularjs/angular-animate.min.js"></script>
<!--App.js which is first file to be declared first -->
<script type="text/javascript" src="/js/application/App.js"></script>
<!--Factories -->
<script type="text/javascript" src="/js/application/factories/Resource.js"></script>
<!--Factories Implementation-->
<script type="text/javascript" src="/js/application/factories/implementation/ResourceImplementation.js"></script>
<!--Services -->
<script type="text/javascript" src="/js/application/utilities/HTTPResource.js"></script>
<script type="text/javascript" src="/js/application/services/ApplicationConstants.js"></script>
<script type="text/javascript" src="/js/application/services/ApplicationLoaderService.js"></script>
<script type="text/javascript" src="/js/application/services/FileUploadService.js"></script>
<!-- Application controllers -->
<script type="text/javascript" src="/js/application/controllers/ApplicationController.js"></script>
<script type="text/javascript" src="/js/application/controllers/AdminViewController.js"></script>
<!--Directives -->
<script type="text/javascript" src="/js/application/directives/common/controls/LoadingScreen.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/FormTextBox.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/ViewFormTextBox.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/FormTextArea.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/FormCheckBox.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/ViewFormCheckBox.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/MenuPullDown.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/ViewDropdownBoxData.js"></script>
<script type="text/javascript" src="/js/application/directives/common/controls/DropdownBox.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/AddressViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/AddressEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/ImageUploader.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/ImageViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/ImageEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/VideoPlayer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/VideoUploader.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/VideoViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/VideoEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/ContentUploader.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/ContentViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/media/HTMLContentEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectTreeEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectArrayTreeEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectTreeViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectArrayTreeViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectArrayEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectArrayViewer.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectFixedArrayEditor.js"></script>
<script type="text/javascript" src="/js/application/directives/common/others/ObjectFixedArrayViewer.js"></script>
Please note; since I have different view in application therefore ideally I am not require to load all the js files. I know this is not the ideal way to load js files. However I don't know what is correct way. I tried to explore the require.js, common.js and browserify.js however not able to map the best solution for this problem.
Please advice the correct way to load the js files related to Angularjs view to allow browser to laod the js files required for that view only.