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

Loading the script async #8

Open
mihaifm opened this issue Jul 10, 2013 · 0 comments
Open

Loading the script async #8

mihaifm opened this issue Jul 10, 2013 · 0 comments

Comments

@mihaifm
Copy link

mihaifm commented Jul 10, 2013

You are suggesting to load the script using document.write, however this is a blocking operation, as described here:

http://www.stevesouders.com/blog/2012/04/10/dont-docwrite-scripts/
http://css-tricks.com/thinking-async/

When the server (the Livereload app) is not running, the browser simply waits for the connection to time out before continuing to render the page. This is especially frustrating on mobile, where it seems to take like forever to load a page.

The solution would be to use the async attribute, or to insert the script element dynamically in the DOM, as mentioned in the posts above.

I'm using this snippet:

<script>
(function() {
    var l = document.createElement("script");
    l.async = true;
    l.src = 'http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(l, s);
})();
</script>

Cheers!

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

1 participant