muratcorlu / ngx-script-loader

Angular 3rd party script loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using ngx-script-loader vs plain js

mackelito opened this issue · comments

Is there pro/cons in using this service vs just do something like

(function (n, t, i, r, u, f, e) { n[u] = n[u] || function() { (n[u].q = n[u].q || []).push(arguments)}; f = t.createElement(i); e = t.getElementsByTagName(i)[0]; f.async = 1; f.src = r; e.parentNode.insertBefore(f, e)})(window, document, "script", "https://urlForTheScript.min.js");

This library is a set of helpers for adding external js dependencies to your angular applications via RxJS streams or via a component in html directly. Basically, if you just need to add a JS reference to your document, you can just use code that you mentioned. But if you need this in multiple places in your Angular app and also want to have callbacks to bind load/error events, you will need to write a service in anycase. Also if you need to add multiple js files in parallel or in a queue, using RxJS will simplify your code. And this library aims to provide these functionalities.

If this is enough for your use case, of course you should just use it. :)

Is this a clear answer for you? @mackelito

Yepp! thx..!