Giter Club home page Giter Club logo

domready's Introduction

domReady

An AMD loader plugin for detecting DOM ready.

Known to work in RequireJS, but should work in other AMD loaders that support the same loader plugin API.

Docs

See the RequireJS API "Page Load Event Support/DOM Ready" section.

Latest release

The latest release will be available from the "latest" tag.

License

MIT

Code of Conduct

jQuery Foundation Code of Conduct.

Where are the tests?

They are in the requirejs and r.js repos.

History

This plugin was in the requirejs repo up until the requirejs 2.0 release.

Contributing

domReady follows the same contribution model as requirejs and is considered a sub-project of requirejs.

domready's People

Contributors

avindra avatar jrburke avatar viskin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

domready's Issues

Intermittent "Script error for: domReady"

In Firefox 37.0.1 and Chromium 41.0.2272.76, I get this error when loading my require.js app with domReady during the page load:

Error: Script error for: domReady
http://requirejs.org/docs/errors.html#scripterror

Then, when I refresh, the error doesn't occur again.

Many users on my site are getting this error, logged with a ravenjs/sentry setup.

document.readyState undefined

Older browsers do not set the document.readyState property. So I usually change your code. Is it possible to provide similar checks in the native code?

   //Check if document already complete, and if so, just trigger page load
    //listeners. Latest webkit browsers also use "interactive", and
    //will fire the onDOMContentLoaded before "interactive" but not after
    //entering "interactive" or "complete". More details:
    //http://dev.w3.org/html5/spec/the-end.html#the-end
    //http://stackoverflow.com/questions/3665561/document-readystate-of-interactive-vs-ondomcontentloaded
    //Hmm, this is more complicated on further use, see "firing too early"
    //bug: https://github.com/requirejs/domReady/issues/1
    //so removing the || document.readyState === "interactive" test.
    //There is still a window.onload binding that should get fired if
    //DOMContentLoaded is missed.
    if (document.readyState === "complete" || ! document.readyState) {
    //-------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^
        pageLoaded();
    }

Bug, fired to early on Webkit

Hello,

There is a bug in your domReady plugin, in line 58 :

document.addEventListener("DOMContentLoaded", pageLoaded, false);

In this case, you are not sure that the DOM can be manipulate (I experienced some problem with jQuery and lazyloading).
To be sure that the DOM can be manipulate you must execute pageLoaded in async mode :

document.addEventListener("DOMContentLoaded", function(){setTimeout(pageLoaded, 1);}, false);

Aside from that, I worked at monde.fr, we use require and it's really great. Thanks for your work.

Line 24: callbacks[i] is not a function

Hey All,

On line 24...

    function runCallbacks(callbacks) {
        var i;
        for (i = 0; i < callbacks.length; i += 1) {
            callbacks[i](doc); // HERE
        }
    }

...I'm getting the following error:

TypeError: callbacks[i] is not a function
    callbacks[i](doc);

Anyone seen this before? Any ideas?

Thanks for your help.

Sincerely,
Keith kjm

Check for document.readyState === "interactive"

Hey there,

is there a reason for the initial check in line 91 is only for 'complete', not also for 'interactive'. Since 'interactive' marks the state of having sent the DOMContentLoaded event it seems appropriate to me.

In my setup domReady seems to initialize shortly after the DOMContentLoaded event has fired and therefore waits all the way till the window.load event fires. Because of some big images on the site this means a lot of time.

Thanks for your opinion
Tobi

New /updated tag so the bower.json file works

While a bower.json file was added as pull request #14 the 2.0.1 tag is still marking a previous commit so when bower pulls tag 2.0.1 the bower.json file is missing. Can you please either update the tag or tag with 2.0.2 or something so this is fixed?

Installable via NPM?

NPM reports another package under the 'domready' handle. Is this one installable via NPM?

Issue with yarn

Not sure if this is directly related to domReady... but, given a package.json configuration:

{
  "devDependencies": {
    "domReady": "github:requirejs/domReady"
  }
}

Yarn install fails, because (I'm guessing here) it can't find the right package on NPM:

error An unexpected error occurred: "ENOENT: no such file or directory, lstat '/Users/username/Library/Caches/Yarn/npm-domReady-2.0.1-3ab6964ba262be995e56452d91b6342f025d30ef'".

I'm wondering, could this library be published properly to NPM? I know npm and yarn can resolve github URLs, but it's nicer having things in NPM when looking things up.

Update isBrowser?

In require.js you use:

isBrowser = !!(typeof window !== 'undefined' && navigator && document)

This may be an intentional difference, but I didn't manage to track down a reason for it.

Thanks

domReady! dependent code fails to execute

It appears that code that has domReady! as a dependency will never be called if there is a call to require.config({}) later.

<!DOCTYPE html>
<html>
<head>
    <script data-main="/static/js/app-test.js" src="/static/js/lib/require.js">
    </script>
</head>
<body>Testing</body>
</html>
// app-test.js
require(['domReady'], function(domReady){
    domReady( function(){
        console.log('domReady plugin callback fired at ' + new Date().getTime() );
    });
});

require(['domReady!'], function(){
    console.log( 'domReady! plugin fired at ' + new Date().getTime() );
});

require.config({ });

Results in:

domReady plugin callback fired at 1343740124501 app-test.js:3
Uncaught Error: Load timeout for modules: domReady!_unnormalized2_unnormalized3
http://requirejs.org/docs/errors.html#timeout require.js:192

Of course, it is odd to call require.config() in this manner, but this was the simplest example I could find that demonstrates the issue. In real code, I have a require.config() call in a separate javascript file that is included on some pages. None of the code in my first module was executing when the second file was required.

I have tested this is Chrome and Safari on OS/X, using RequireJS 2.0.4 and domReady 2.0.0.

BTW, thanks for writing, releasing and maintaining RequireJS!

domReady firing to early on IE

I'm running IE9 and the domReady plugin is firing early.

I stepped through the code and tracked it down.

    //Check if document already complete, and if so, just trigger page load
    //listeners. Latest webkit browsers also use "interactive", and
    //will fire the onDOMContentLoaded before "interactive" but not after
    //entering "interactive" or "complete". More details:
    //http://dev.w3.org/html5/spec/the-end.html#the-end
    //http://stackoverflow.com/questions/3665561/document-readystate-of-interactive-vs-ondomcontentloaded
    if (document.readyState === "complete" ||
        document.readyState === "interactive") {
        pageLoaded();
    }

For some reason IE9 is setting the readyState to interactive before it even parses the <body>. Here is what I found when I had a break point on pageLoaded();

window.document.getElementsByTagName('head') 
{
0 : {...},
length : 1,
item :  function item() {     [native code] } ,
namedItem :  function namedItem() {     [native code] } 
} 

So the document has a head at that point as it should.

window.document.getElementsByTagName('body') 
{
length : 0,
item :  function item() {     [native code] } ,
namedItem :  function namedItem() {     [native code] } 
} 

But the body doesn't even exist yet and it has the readyState === "interactive"

This is an issue I ran into a long while ago. I originally submitted a pull request to add document.readyState === "interactive" as one of the valid readyStates. requirejs/requirejs#137. I ran it in production for a while and would randomly see dom load errors on IE. This caused me to back it out. So I think we need to remove the readyState === "interactive" check.

Raul

Bower package?

Can you create a bower component package for domReady like you did for RequireJS and RequireJS-text?

Thanks much,
Cary

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.