Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load external libraries from CDN with angular-cli

I would like to use the angular-cli to build an app that bundles my app code but does not include the Angular2 framework or other large external JavaScript libraries in the bundled code. I would like to load these libraries from a CDN when the page loads. Is there a way to do this?

Also, is there a way to do this while preserving the benefits of a local build where only the parts of the Angular2 framework that I am using gets loaded?

I saw this question, but it was for SystemJS and I don't think it applies to Angular-cli: How to load angular2 using CDN and SystemJS

like image 502
Chris Avatar asked Jan 17 '17 16:01

Chris


People also ask

Can I use angular with CDN?

AngularJS moduleThis AngularJS CDN integration method allows for your images to be easily delivered via a CDN instead of locally from the origin server. The below snippet demonstrates the required configuration within your app to use this module.

What is angular CDN?

AngularJs CDN is ideal for delivering the files efficiently, and it allows the user to retrieve the data from the most optimal CDN server rather than from the original server. The AngularJs CDN integration has so many advantages, such as HTTP/2-supported servers, CORS, an extensive network of data centers, etc.

What is library CDN?

This topic describes the Sitecore Media Library Content Delivery Network (CDN) and how it helps increase performance and availability for your solution. The CDN is a distributed network platform, which is optimized to deliver web contents efficiently to clients.


1 Answers

You simply need to add the appropriate <script src=""> tags pointing to the CDN to the index.html file. Remember to remove the .js files from angular-cli.json so they don't get bundled with the app.

Currently, you can't do that for the Angular 2 js files itself, they are automatically bundled with your app. Though the latest updates enable the web servers and browsers to cache the vendor files, so they don't get redownloaded on every visist to your app but only when the hash changes.

like image 88
Alexander Ciesielski Avatar answered Sep 24 '22 09:09

Alexander Ciesielski