I am not sure how to do this with Browserify, as I have never tried this myself, but I highly recommend that you take a look at ocLazyLoad .
As a standalone service, it works with download files (json, css, js, templates - you name it) and enter them into an already running angular application.
With this in mind, it works even better (imo) in combination with a router (default is angular one or ui-router).
There are several “seed projects" that demonstrate how this can be done with ocLazyLoad in conjunction with SystemJS.
But you don’t even need it.
If you go with ui-router, ui-router-extras and ocLazyLoad, you can add something like this to the lazy load states:
main.js
var main = angular.module('main', [ 'ui.router', 'ct.ui.router.extras.future', 'oc.lazyLoad' ]); main.constant('lazyLoadedStates', [ { name: 'about', url: '/about', type: 'lazy', src: [ '/path/to/about.module.js', '/path/to/AboutController.js' ] } ]); main.config(function ($futureStateProvider, lazyLoadedStates) { $futureStateProvider.stateFactory('lazy', function ($q, $ocLazyLoad, futureState) { var deferred = $q.defer(); $ocLazyLoad.load(futureState.src).then(function () { deferred.resolve(); }); return deferred.promise; }); lazyLoadedStates.forEach($futureStateProvider.futureState); });
With the "framework" aside - now you just need to add additional modules, with a lot of code, and map the real state definition to the dummy in the constant lazyLoadedStates .
about.module.js
angular.module('about', []).config(function ($stateProvider) { $stateProvider.state('about', { url: '/about', controller: 'AboutController', template: 'some_template.html' }); });
AboutController.js
/** * Register the AboutController in a lazy loaded file. This could be done in about.module.js aswell, * but we'll do it here to separate stuff and showcase loading of multiple files. */ angular.module('about').controller('AboutController', function ($state) { console.log('Im on a lazy loaded state!', $state.current); });
Hope this gives you a general idea on how to set up lazy loaded states in Angular. I have yet to find an easier way to do this, but I'm sure there are articles on how to associate ui-router (or the default angular router) with some other “lazy bootloader”.
Doc Links: