Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async script and serie #95

Closed
koryp opened this issue Nov 19, 2014 · 3 comments
Closed

async script and serie #95

koryp opened this issue Nov 19, 2014 · 3 comments
Labels

Comments

@koryp
Copy link

koryp commented Nov 19, 2014

Great module! Thank you!!!

I'm loading my custom angular module along with a few dependencies (specifically, jquery then a jq plugin) and so I'm using the serie config option to make sure jquery is ready for the plugin.

But, it appears the buildElement function always includes the async attribute for scripts and my jq plugin seems to be getting executed before jquery finishes loading.

I was able to fix this locally by changing line 111 from:
el.async = 1;
to:
el.async = (params.serie?0:1);

Alternatively, maybe the async attribute could be conditionally removed using a parameter in the load config...

Is this an appropriate fix or is there another approach using ocLazyLoad to avoid async scripts from executing out of sequence?

koryp added a commit to thenewgroup/newplayer that referenced this issue Nov 20, 2014
@ocombe ocombe added the bug label Nov 20, 2014
@ocombe
Copy link
Owner

ocombe commented Nov 20, 2014

Hmm that's weird because the serie param is supposed to make the lib wait for the script to have been effectively loaded (when the onload event has been called) to include the next script.
I'll take a look at this tonight, thanks !

@koryp
Copy link
Author

koryp commented Nov 20, 2014

I think the serie param is correctly waiting for the js file to load before proceeding to the next one.
But the async attribute on the script tag, as I understand it, allows DOM rendering to continue, including loading and processing other scripts.
Without the async attribute, scripts are loaded and fully executed before the browser proceeds to the next tag (script or otherwise).
So, my suspicion is that the jquery library is still being processed asynchronously and, in the meantime, the plugin was loaded and executed before jquery was fully initialized.

@ocombe
Copy link
Owner

ocombe commented Nov 20, 2014

Ah yes that would make sense !

@ocombe ocombe closed this as completed in 9af93ed Nov 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants