简体   繁体   中英

AngularJS app deployment best practices? Use a CDN?

What are the best practices to deploy in production an AngularJS App? Is using a CDN the way to go?

An AngularJS app is afterall only static files so instead of having NodeJS or even Nginx serve the files, it looks like it'd be better to just use a CDN to not worry about all these static files and focus on running the API backend that the AngularJS app would use.

I would like to get to the point where I can have 2 distinct projects: - one being only the AngularJS app - one being only the API backend served by NodeJS

I am having a hard time to see how to setup such a development environment that would be easy to deploy in production as well. I am new to AngularJS/NodeJS and all the tutorials I have found put everything together.

Any advice? Examples?

Thanks

You can definitely use a CDN, or anything that acts the same way – Amazon S3 is a common solution, but the simplest is probably GitHub Pages : Just make sure your files are organized the way they want them (in a branch called "gh-pages" and it should work fine.

You'll run into issues here if you have modules you depend on: You can either download all your dependencies (the stuff that you get when you run npm install or bower install , for example), or you can make sure all of the JavaScript files you reference are either in your repo or pointing at CDNs.

An example – instead of including this:

<script src="node_modules/angularjs/angularjs-1.5.4.min.js"></script>

You'd want this:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>

There are lots of places to find hosted versions of JS modules; Google is one, and CDN.js is handy as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM