0

I am writting an app from scratch in Angular with node.js and I was wondering if I am doing things correctly.

I want to split the content of my index into smaller html modules with their respective controllers, this way, everything will look more structured and easy to find when the project gets bigger.

For example :

  • index.html <--- main file
  • /views/menu.html <--- menu module
  • /views/content.html
  • /js/menu.js <---controller for the html module
  • /js/content.js ...

I can manage those files by just adding ng-include :

e.g

< ng-include src=" 'views/menu.html' ">

My concern is that this is like a GET request per file and I was wondering if this would affect the load speed of my application. Because I am working in local, this loads in 2ms which is very quick but I was wondering how this would behave online.

My questions are :

  • Is this the best way to create a modular app with different html files and js controllers ?
  • Is there a better way to achieve what I want to do ?

I am still learning Angular, sorry if this is too basic.

Thanks

2 Answers 2

3

Its better to use index.html as basic load file which will load all css and js on the load of the app,

for ex:- you can make diffrent app for login and after login section. After login. load all the js and css files through the app after login..it will improve the loading time and also be a modular

Sign up to request clarification or add additional context in comments.

Comments

2

as suggested by @Dhruv Raj Singh It is good to use a different ng-app for pre-login and post-login. It is always good to structure the code that you want.

Now ng-include will Emitted event $includeContentRequested every time the ngInclude content is requested.

Now it up to the requirement use cases how to use and when to use.

If the module is a sperate and special one which requires lots of resources specific to it only and will be used by few users and only few times then it is better to include them for that module only

else common resources should be included at ng-app level.

You can name and organised the resources whatever way you want but include them at post-login app creation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.