Suppose I have:
<script src="script1.js"></script>
<script src="script2.js"></script>
Both of these scripts have ready() inside. Will the code in script2.js’s ready() always execute after the first one?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes.
First of all, the code in
script2.jswill be executed afterscript1.js, as it comes later in the document (and thedeferattribute is not set).Furthermore, the implementation [source] of the
readyfunction is:where
readyListseems to be [source] a deferred object [docs]. That means the callbacks are executed in the order they have been added to that object.