10 Jun Resource Lazy Loading With Angular
Using ocLazyLoad in your project
Luckily for our problem, there is a library out there to solve this issue and save us from our headache. The ocLacyLoad library is designed to do just that. It is an open source project that is gaining popularity in recent days. You can visit their website here [https://oclazyload.readme.io/].
For example, let’s take a look at this Angular route.
To solve our problem, we define a ‘resolve’ parameter for the state. Before loading the state, Angular will determine the value of this parameter. We can define the required resources for the page here. In this case, we loads ‘ContactUsController.js’ right when we need it. That’s it. Our problem is gone.