0

I'm not really sure how to word this so it's making it hard to search but if I have a big application and each component is in it's own js file, then it doesn't make sense to load ALL component files in index.html. The user might never even see a large number of these components as they are navigating through the app.

So the question would be, how can we load components as they are needed in a view that houses them vs all at once?

In a perfect world, as a page is routed it would know the components on the view and know if it's already registered that component and if not, go get the js file to do so and register it automatically for us before running the view. This would require some kind of configuration that says this string component name is this js file on the server.

Does anything like this exist?

user441521
  • 6,942
  • 23
  • 88
  • 160
  • Posting as a comment as your use case is unclear but... You could partition your application into multiple apps and bootstrap manually. https://stackoverflow.com/questions/18571301/angularjs-multiple-ng-app-within-a-page – mccainz Oct 18 '17 at 15:40
  • I guess the use case is just I don't want to load the entire app and all components in index.html since it could be a waste and slow for big apps if a user doesn't use many of the components because they just don't end up navigating to views that have said components on them. Would multiple apps even matter? One would still need to include all the js/css file up front wouldn't they? – user441521 Oct 18 '17 at 15:48

1 Answers1

1

Looks like it's called lazy loading of scripts. There seems to be a really easy angular module for this!

https://oclazyload.readme.io/

Very cool and close to what I was hoping for. Ideally I'd love for config of components and then dynamic loading of components when the view uses then but this is close enough. Perhaps I can enhance this to pre-read the view html looking for components that aren't registered with angular already and then search the config to get them if not.

user441521
  • 6,942
  • 23
  • 88
  • 160