JohnTheBeloved
JohnTheBeloved

Reputation: 2433

Bootstrapping AngularJS javascript files through one javascript file

I am new to AngularJS, but with the little I have learn't and worked it, I aprreciate it has a fantastic client side framework, However I dont like it when I have to include all the files I need in my my index Page for instance

<script src="/js/lib/angular/ng-core/angular.js"></script>
<script src="/js/lib/angular/ng-module/angular-route.js"></script>
<script src="/js/lib/angular/controller/main.js"></script>
<script src="/js/lib/angular/controller/home.js"></script>
<script src="/js/lib/angular/controller/insuranceType.js"></script>
<script src="/js/lib/angular/controller/insuranceCategory.js"></script>
<script src="/js/lib/angular/config/router.js"></script>

A user can just check source and download my project like this,

how can load only a javascript and in that I can bootstrap all my required angular javascript files? An idea is what I put below

My Index.html Page

<!DOCTYPE html>
<html>
<head>
  ...
    <script src="bootstrapmyfiles.js"></script>
  ...
</head>
</html>
<body>
</body>

My bootstrapmyfiles.js File

 //pseudocode here
 require("angular.js")
 //require other javascript files too

How can I achieve this please, Is there a way? seen this question but not satisfactory

Upvotes: 0

Views: 62

Answers (2)

Blackus
Blackus

Reputation: 7203

You can use Grunt to compile (and minify/uglify, if you want it) all your javascript files into only one when releasing your application.

Upvotes: 0

Aleksandr Ivanov
Aleksandr Ivanov

Reputation: 2786

There are at least 2 ways of bootstrapping angular files:

Download files asynchronously from client when needed. Angular itself doesn't provide such feature, but you can try to combine it with something like RequireJS. For example check this article. By the way Angular 2 is promised to be AMD ready.

Prepare files on server. Almost all web frameworks have some kind of bundling mechanism. So you can put all files in one and also minimize them.

A user can just check source and download my project like this

You can't do nothing with that. Files are downloaded on client machine and that means he/she can view them. Putting all files in one bundle and minimizing (obfuscating) them, will make it less readable, but still it's possible to read source.

Upvotes: 1

Related Questions