File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -49,11 +49,13 @@ function appendUnique(script, next) {
4949 * get a listener and when is loaded first and second will be completed.
5050 * @scenario 3: attempt load the same external script after is completed.
5151 */
52- function loadScript ( args ) {
53- const src = args . src
54- const id = args . id
52+ function loadScript ( { src, id, data } ) {
5553 const script = document . createElement ( 'script' )
5654
55+ script . id = id
56+ script . src = src
57+ script . setAttribute ( `data-${ data ? data : 'vendor' } ` , id )
58+
5759 return new Promise ( ( resolve , reject ) => {
5860 // once the lib is registered you can resolve immediatelly
5961 // because it means that is fully loaded
@@ -68,13 +70,15 @@ function loadScript(args) {
6870 } )
6971
7072 script . onerror = function onErrorLoadingScript ( ) {
73+ // Remove the element from the body in case of error
74+ // to give the possibility to try again later
75+ // calling the same function
76+ document . body . removeChild ( script )
7177 reject ( )
7278 }
7379
74- script . id = id
75- script . src = src
7680 appendUnique ( script , resolve )
7781 } )
7882}
7983
80- module . exports = loadScript
84+ export default loadScript
You can’t perform that action at this time.
0 commit comments