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

Do we really need setTimeout? #9

Closed
revyh opened this issue Mar 19, 2016 · 3 comments
Closed

Do we really need setTimeout? #9

revyh opened this issue Mar 19, 2016 · 3 comments

Comments

@revyh
Copy link

revyh commented Mar 19, 2016

Why script injection starts after timeout? It delays downloading of scripts, sometimes significantly. There is almost no delay in Chrome, but in FF and IE9 (that's what I've tested so far) timeout event fired after DOMContentLoaded and thus they have notable lag before starting to download scripts. I tried to delete setTimeut and it removes the lag while the code is still passed all tests.

So, the question is: what for do we use setTimeout? Comment says that timeout "fires after window 'load' event", but it's neither the truth or explanation why.

If you need, I can do some deeper investigation on this.

@amorey
Copy link
Member

amorey commented Mar 20, 2016

The call to setTimeout originally came from this line in ded's original script.js:
https://github.com/ded/script.js/blob/master/src/script.js#L49

The intention was to start the download after the DOMContentLoaded event fires but if the behavior is different depending on the browser then we should remove it.

Can you confirm that using setTimeout executes code before DOMContentLoaded event fires in Chrome but after in FF and IE9?

@amorey
Copy link
Member

amorey commented Mar 20, 2016

The call to setTimeout has been removed in the latest version (v1.6):
8d76a07

@amorey amorey closed this as completed Mar 20, 2016
@revyh
Copy link
Author

revyh commented Mar 21, 2016

Thanks for the quick response! I didn't have enought time to respond you yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants