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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With