managing document.ready event(s) on a large-scale website

后端 未结 9 1539
予麋鹿
予麋鹿 2021-01-30 10:51

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 c

9条回答
  •  难免孤独
    2021-01-30 11:43

    This is what i have done in my rails mvc project with heavy javascript, i have created a separate namespace for the controllers in js which resembles the rails controller

    class BusinessController
       def new
       end  
       def index
       end
    end
    

    and

    Var Business =  {
          init : function(action) {
             //code common to the Business module
             //even add the common jquery doc ready here, its clean
             //and call the page specific action
             this[action]();
          },
          new : function() {
                 // check jquery document ready code here, thats relevant to this action
                 //New rental page specific code here
          },
          index : function() {
                 //  check jquery document ready code here, thats relevant to this action
                 //index rental page specific code here 
          }
    }
    

    and on the view code(server side) just initiate the page specific js code by

    
    

    You can pretty much tweak this to make it work in any language. And this approach doesn't care whether you have a single file or multiple files.

提交回复
热议问题