Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Boost Angular app performance #433

Merged
merged 3 commits into from
May 13, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ module.exports = function (grunt) {
},
javascripts: {
files: ['src/javascripts/ng-admin.js', 'src/javascripts/ng-admin/**/**/*.js', 'src/javascripts/ng-admin/**/**/*.html'],
tasks: ['ngconfig', 'requirejs:dev', 'copy:js_dev', 'copy:es6_dev', 'copy:es6_devmap'],
tasks: ['ngconfig', 'requirejs:dev', 'ngAnnotate', 'copy:js_dev', 'copy:es6_dev', 'copy:es6_devmap'],
options: {
atBegin: true,
livereload: true
Expand Down Expand Up @@ -250,7 +250,7 @@ module.exports = function (grunt) {

grunt.registerTask('test:local', ['mochaTest', 'karma', 'build:dev', 'copy_build:dev', 'test:local:e2e']);
grunt.registerTask('test:local:e2e', ['json_server', 'connect', 'protractor']);
grunt.registerTask('build:dev', ['ngconfig', 'requirejs:dev', 'compass:dev', 'concat:css']);
grunt.registerTask('build:dev', ['ngconfig', 'requirejs:dev', 'ngAnnotate', 'compass:dev', 'concat:css']);
grunt.registerTask('copy_build:dev', ['copy:es6_dev', 'copy:es6_devmap', 'copy:js_dev', 'copy:angular', 'copy:css_dev', 'copy:fonts_dev', 'clean']);

// register default task
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ Your application should use a `ui-view`:
<div ui-view></div>
```

### Production ready

You can enable `ng-strict-di` angular mode to boost your application performance:
```html
<body ng-app="myApp" ng-strict-di>
```

Ng-admin library is already compatible, but you have to explicitly declare dependencies on your custom application code.

Also, ng-admin disable debug mode of Angularjs.

See [Angular documentation](https://docs.angularjs.org/guide/production) for more details about this two tweaks.

## Example Configuration

We chose to define the entities & views directly in JavaScript to allow greater freedom in the configuration.
Expand Down
12 changes: 6 additions & 6 deletions examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var app = angular.module('myApp', ['ng-admin']);

app.config(function (NgAdminConfigurationProvider, RestangularProvider) {
app.config(['NgAdminConfigurationProvider', 'RestangularProvider', function (NgAdminConfigurationProvider, RestangularProvider) {
var nga = NgAdminConfigurationProvider;

function truncate(value) {
Expand Down Expand Up @@ -276,7 +276,7 @@
);

nga.configure(admin);
});
}]);

app.directive('postLink', ['$location', function ($location) {
return {
Expand Down Expand Up @@ -333,7 +333,7 @@
'<div class="col-lg-5"><a class="btn btn-default" ng-click="controller.sendEmail()">Send</a></div>' +
'</div>';

app.config(function ($stateProvider) {
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('send-post', {
parent: 'main',
url: '/sendPost/:id',
Expand All @@ -342,7 +342,7 @@
controllerAs: 'controller',
template: sendPostControllerTemplate
});
});
}]);

// custom page with menu item
var customPageTemplate = '<div class="row"><div class="col-lg-12">' +
Expand All @@ -352,12 +352,12 @@
'<p class="lead">You can add custom pages, too</p>' +
'</div>' +
'</div></div>';
app.config(function ($stateProvider) {
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('stats', {
parent: 'main',
url: '/stats',
template: customPageTemplate
});
});
}]);

}());
2 changes: 1 addition & 1 deletion examples/blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script src="build/ng-admin.js" type="text/javascript"></script>
<script src="config.js" type="text/javascript"></script>
</head>
<body ng-app="myApp">
<body ng-app="myApp" ng-strict-di>
<div ui-view></div>
</body>
</html>
5 changes: 3 additions & 2 deletions src/javascripts/ng-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ define(function (require) {
factory.constant('AdminDescription', new AdminDescription());

var ngadmin = angular.module('ng-admin', ['main', 'crud', 'AdminDescriptionModule']);
ngadmin.config(function(NgAdminConfigurationProvider, AdminDescription) {
ngadmin.config(['NgAdminConfigurationProvider', 'AdminDescription', '$compileProvider', function(NgAdminConfigurationProvider, AdminDescription, $compileProvider) {
$compileProvider.debugInfoEnabled(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be configurable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

NgAdminConfigurationProvider.setAdminDescription(AdminDescription);
});
}]);
});
4 changes: 4 additions & 0 deletions src/javascripts/test/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ exports.config = {
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 360000
},

onPrepare: function () {
browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO"');
}
};