browserify and document ready?

后端 未结 5 1019
慢半拍i
慢半拍i 2021-02-08 00:28

I\'m struggling with using Browserify and document ready events. How do I craft a module that exports content only available after the document ready event has fired? How do I

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-08 01:26

    Instead of listening for a ready event, you can put your browserify bundle in a deferred script tag:

    
    

    This allows you to remove the ready wrapper completely since the bundle will not be executed until the DOM is loaded.

    Unfortunately support of defer is patchy, and I don't recommend it unless you don't have to support IE < 10. Consider this answer one for the future, as browser support for it grows.

提交回复
热议问题