question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

head.ready('<label>') firing before script being loaded if taking too long

See original GitHub issue

I’ve noticed that head.ready seems to fire the “loaded”-event although the script with the specified label hasn’t even loaded fully. This is especially impacting slow connections and big scripts like e.g. jQuery. In my opinion there seems to be something fundamentally broken in head.js

I’ve made a proof of concept (which is also on http://playground.herndl.org/headjs_330/)

<?php

if (isset($_GET['js'])) {
    $js = $_GET['js'];

    header('Content-Type: text/javascript');

    if ($js == 'fast')
        echo 'debug("loaded script \'fast\'");';
    else if ($js == 'slow') {
        sleep(10);
        echo 'debug("loaded script \'slow\'");';
    }
    exit;
}

?>
<!DOCTYPE html>
<html>
<head>
    <title><?php echo $_SERVER['SERVER_NAME']; ?></title>
    <meta charset=UTF-8>
    <script type="text/javascript" src="head.min.js"></script>
</head>
<body>
    <pre id="output"></pre>
    <script type="text/javascript">
        function debug(text) {
            //console.log(text); // this does not work in old IE
            document.getElementById('output').innerHTML += '<br>' + text;
        }
        head.ready('fast', function() {
            debug("'fast' ready event fired");
        });
        head.ready('slow', function() {
            debug("'slow' ready event fired");
        });

        debug("start loading script 'fast' and 'slow'");
        head.load({fast: '?js=fast'}, {slow: '?js=slow'});
    </script>
</body>
</html>

It outputs

start loading script ‘fast’ and ‘slow’ loaded script ‘fast’ ‘fast’ ready event fired ‘slow’ ready event fired loaded script ‘slow’

I would love to see this getting fixed as well as the other open issues here on github, but the project seems to be dead?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
SiteSplatcommented, Mar 30, 2015

I noticed this too. I also posted a request of info about future planning. it really REALLY would be nice if the original developer or whoever is working this to pop by and say something. I don’t understand why its so difficult to be transparent. login into your github account and say something pretty please? post on the blog? twitter? For pete’s sake its 2015! @WhoeverTheHeckIsDeveloping/SupportingHeadJS

1reaction
chrisbenselercommented, Jan 27, 2017

Same thing here. Still happening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does $.ready fire before or after all inline <script>'s have been ...
Yes and yes. The execution of <script> elements is synchronous except when using the HTML5 "async" attribute. The synchronous execution of ...
Read more >
Page: DOMContentLoaded, load, beforeunload, unload
When the browser processes an HTML-document and comes across a <script> tag, it needs to execute before continuing building the DOM.
Read more >
1. Loading and Execution - High Performance JavaScript [Book]
The longer JavaScript takes to execute, the longer it takes before the browser is free to respond to user input. On a basic...
Read more >
Document: DOMContentLoaded event - Web APIs | MDN
DOMContentLoaded may fire before your script has a chance to run, so it is wise to check before adding a listener. function doSomething()...
Read more >
The window.onload Problem (Still) - peter.michaux.ca
Using some apparent browser behavior that defers until after the DOM is ready is a hack at best. The intent of DOMContentLoaded is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found