More information about the Underscore mailing list

[_] fat javascript and flckering

Adam Alton adam.alton at
Thu Dec 3 13:55:15 GMT 2009

 > <script type='text/javascript'>$('html').addClass('js');</script>
We use this technique a lot, it's really powerful, and means that if  
you're using Javascript to turn ugly things into sexy things you don't  
need to wait for the whole page to load and your JS to run before the  
ugly stuff gets hidden.  You can put all of your JS at the bottom of  
the page, so that it gets loaded after page render, but things that  
you want to hide for JS users are hidden before they are rendered.
I would actually do:
document.getElementsByTagName('html')[0].id = 'hasJS';
which means that:
a) you don't need to put the jQuery library <script> in the <head>,  
you can put it at the bottom of the <body>, so the content loads  
faster and jQuery niceness comes at the end, and
b) giving it an id rather than a class gives it more CSS specifity  
which in this case is usually a good thing.

Is the flickering caused by the browser not bothering to download  
images until you do $('body').show(); ?  Do browsers load background  
images for elements that are display:none?