Hello, community!
I wonder if it's a good idea to use ocLazyLoad to load the controllers of an application (Single Page Application - SPA) from AngularJS .
I'm using UI Router instead of ngRoute .
The code I have works perfectly (in the example, it's simplified, just for demonstration purposes).
'use strict';
var minhaAplicacao = angular.module('minhaAplicacao', ['oc.lazyLoad', 'ui.router']);
angular.module('minhaAplicacao').config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'partials/home/home.html',
data: {pageTitle: 'Home'},
resolve: {
service: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load({
serie: true,
files: [
'partials/home/home.controller.js'
]
});
}]
}
});
<!DOCTYPE html>
<html ng-app="minhaAplicacao">
<head>
<meta charset="utf-8">
<title data-ng-bind="'GEOPS | ' + $state.current.data.pageTitle">GEOPS</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="bower/vendor/bootstrap-3.3.6/css/bootstrap.min.css">
</head>
<body>
<div ui-view></div>
<script src="path/to/angular.js"></script>
<script src="path/to/ocLazyLoad.js"></script>
<script src="path/to/ui-router.js"></script>
</body>
</html>
My question is about the implications of this practice.
Is it wrong to do lazyloading of controllers AngularJS?
Is there a security or scalability issue in this type of practice?