muratcorlu / ngx-script-loader

Angular 3rd party script loader
MIT License
33 stars 6 forks source link

Using ngx-script-loader vs plain js #10

Closed mackelito closed 6 years ago

mackelito commented 6 years ago

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");

muratcorlu commented 6 years ago

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. :)

muratcorlu commented 6 years ago

Is this a clear answer for you? @mackelito

mackelito commented 6 years ago

Yepp! thx..!