Create a gist now

Instantly share code, notes, and snippets.

Moar smallest DOMReady code, EVAR!
function r(f){setTimeout(/in/(document.readyState)?r:f,9,f)}
@ded
ded commented Feb 24, 2011

is that just the same above? my eyes are going crazy from seeing the same vars for 12 hours! haha

@tobie
Owner
tobie commented Feb 24, 2011

This one does:

function r(f) {
  var fn = /in/(document.readyState) ? f : r;
  setTimeout(fn, 9, f);
}

The previous one did:

function r(f) {
  var fn = /in/(document.readyState) ? f : r;
  setTimeout(fn); // <-- Look ma, no arguments!!
}

which is of course wrong.

@tobie
Owner
tobie commented Feb 24, 2011

Fixed the inverted ternary expression.

@jed
jed commented Feb 25, 2011

wait, now you're gonna make me wait nine whole milliseconds even if the document is already ready? COME ON, TOBIE!

@ded
ded commented Feb 25, 2011

hahahaha! this never stops being entertaining. i gave up on the short war. the original hope was to make my general doc ready method smaller. and it still had to be x-browser. thus

  • the no arg thing does not work in IE (it requires 2)
  • the third arg in IE is not an arg list (it specifies language)

so, the ONLY way to use setTimeout (x-b) is with a function, and a required integer. (But I think we all knew that after a certain point)

@jed
jed commented Feb 25, 2011

the third argument in IE is language? that is insanity.

the short war isn't fruitless though, since it's pretty instructive.

i'm curious, though; why do you use domContentLoaded to fix readyState in FF 3.6 instead of just using it as the domready function?

@ded
ded commented Feb 25, 2011

i use it to fix FF <=3.5, because they had no proper readyState.

@jed
jed commented Feb 25, 2011

right, but why fix it at all if all you need to know is when the document content is loaded? after all, the polling is only a fallback for a real domContentLoaded, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment