1

I would like to use an external JS library into my Angular 11 project created using the Angular-CLI.

From many answers (1, 2, 3), I see that one way to achieve this is by adding the path to the JS file into the scripts section of angular.json file, and add variable declarations in typings.d.ts file (I should create one if it does not exist).

However, I would like to be able to load it with a "defer" attribute, namely when the page has finished parsing, as in the documentation of this library it reads:

Don't forget the defer attribute. It reduces the loading time of your page.

From the official Angular docs page on this section, there does not seem to be an option to add this attribute, and I don't understand when these external libraries are loaded. I was wondering if anyone can help me understanding this.

umbe1987
  • 2,894
  • 6
  • 35
  • 63

1 Answers1

-1

You can add anything you like into the index.html. Even a script with defer attribute.

Whether that is the best way to include the script into your project is up to you.

kvetis
  • 6,682
  • 1
  • 28
  • 48