ded / domready

lets you know when the dom is ready
MIT License
874 stars 129 forks source link

add support for server-side #27

Closed ahdinosaur closed 10 years ago

ahdinosaur commented 10 years ago

hi! thanks for domready. :)

in order to make it easier to share code on the client and server, it'd be nice if domready didn't error whenever called on the server.

ded commented 10 years ago

what context and purpose does this serve on the server side?

ahdinosaur commented 10 years ago

the context is when you share code on the client and server and this code has calls to domready in it, not that domready is useful on the server but that it is coupled with other useful code. the purpose is to make domready friendlier so as not to throw a Reference Error when called on the server.

to be honest though, a better solution is to do the reverse if check in the shared code and not in domready:

if (typeof document !== 'undefined') {
  domready(function () {
    Backbone.history.start() // or whatever
  });
}

maybe this issue can be a guide to anyone who also runs into this error.

cheers! :)

ded commented 10 years ago

No worries. My recommendation is to simply not even load this code on the server since it clearly isn't sharable. But don't get me wrong, I'm all for shareable libs, this just isn't one of them