ina
ina

Reputation: 19534

Bootstrap javascript at very end and jQuery $(document).ready

Much of jQuery depends on $(document).ready ... why does bootstrap 2.0 include the javascript library calls at the very end?

Is there a way to get $(document).ready to work keeping the js lib calls at the very end?


Update: A common example (and the source of my frustration!) is $("#id").click(), which does not seem to work if you do not place it inside the .ready function...

Upvotes: 1

Views: 7312

Answers (2)

collymitch
collymitch

Reputation: 105

I expect it loads it at the end of the file to improve the performance - see Yahoo best practices.

Can you put your own JS script tag after the jQuery load? If you put it after the jQuery load it should work and it should also allow your page to display whilst your code is loaded.

Upvotes: 0

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

jQuery only "depends" on $(document).ready() to support scripts that are evaluated while the document is still being loaded (e.g. scripts residing in the document's <head> or halfway through its <body>).

Placing scripts at the end ensures the rest of the document is loaded by the time the scripts are evaluated, so $(document).ready() is not necessary in that case.

Upvotes: 4

Related Questions