且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 angular-cli 从 CDN 加载外部库

更新时间:2023-09-30 10:45:04

您只需将指向 CDN 的适当 <script src=""> 标签添加到 index.html 文件.请记住从 angular-cli.json 中删除 .js 文件,以免它们与应用程序捆绑在一起.

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.

目前,您无法对 Angular 2 js 文件本身执行此操作,它们会自动与您的应用程序捆绑在一起.尽管最新的更新使网络服务器和浏览器能够缓存供应商文件,因此它们不会在每次访问您的应用时重新下载,而只会在哈希更改时重新下载.

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.