Requirejs domReady plugin vs Jquery $(document).ready()?

后端 未结 5 1156
野性不改
野性不改 2020-12-07 07:29

I am using RequireJS and need to initialize something on DOM ready. Now, RequireJS provides the domReady plugin, but we already have jQuery\'s $(document).ready()

5条回答
  •  长情又很酷
    2020-12-07 08:00

    I found I do this as part of the main entry so that all of my javascript is guaranteed that the DOM is ready and jquery is loaded. Not sure how great this is so welcome any feedback but here's my main.js:

    require(['domReady!'], function(domReady){
        console.log('dom is ready');
        require(['jquery', 'bootstrap'], function(){
            console.log('jquery loaded');
            require(['app'], function(app){
                console.log('app loaded');
            });
        });
    });
    

提交回复
热议问题