Note that there are some explanatory texts on larger screens.

plurals
  1. POmanaging document.ready event(s) on a large-scale website
    primarykey
    data
    text
    <p><strong>NOTE: I have now created a jQuery plugin which is my attempt of a solution to this issue. I am sure that it could be improved and i've probably overlooked lots of use cases, so if anyone wants to give feedback feel free :-) <a href="https://github.com/WickyNilliams/ReadyBinder" rel="noreferrer">https://github.com/WickyNilliams/ReadyBinder</a></strong></p> <p>I don't have a problem as such, but thought this would be an interesting point for discussion, and i hope people have some interesting ideas for this.</p> <p>Basically, i work on a large-scale website and increasingly we are writing more and more JavaScript. This is fine, i enjoy JS' unique approach and i find the quirkiness in some of the darker annals of the language to be endearing ;-) However one thing that has always bugged me is how to manage document ready events as they get increasingly large over time (and as a result less focused/specific to the page being served)</p> <p>The problem is that we have one JS file (merged &amp; minified, though that's kind of inconsequential for my questions). Most of the JS is written using the revealing module pattern, and jQuery is our framework of choice. So all our JS funcitonality is logically grouped into methods, namespaced, and then right at bottom of the script file we have this</p> <pre><code>$(function(){ //lots of code here, usually calling encapsulated methods //on our namespaced revealing module }); </code></pre> <p>The problem is that not all of the code in this document ready handler pertains to every page. For instance, on one page only 10% of it might be relevant, on another perhaps 80% might be relevant. To me, this feels incredibly wrong, i feel i should only execute the code i need per page, mainly for efficiency, but also maintainability.</p> <p>I've searched google for approaches to this issue, but cannot find anything, maybe i'm just searching for the wrong thing!</p> <p>Anyway, so my questions are:</p> <ul> <li>Has anybody ever thought about this issue?</li> <li>Is it actually an issue in other people's opinion?</li> <li>Do you have a large, all-encompassing document ready handler in your code or is it more focused for the type of page being served?</li> <li>If the latter, how do you manage this? Multiple handlers which get switched in JS or dynamically spitting out the document ready handler server-side?</li> </ul> <p>Look forward to people's thoughts on the matter.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload