-
-
Notifications
You must be signed in to change notification settings - Fork 213
remove $(document).ready() #8017
remove $(document).ready() #8017
Conversation
|
This may be right, but since we don't know, why not leave the function call there? Does it noticeably affect the performance? |
|
It does not affect the performance that much, just a bit. |
http://stackoverflow.com/questions/6026645/document-readyfunction-vs-script-at-the-bottom-of-page |
|
I know. But can we be sure that the scripts are always at the bottom of the page? What if someone adds a module via insert tag? |
|
What if something is included with |
|
@contao/developers /cc |
|
We can safely remove them. That's my opinion :) |
|
I would not remove them. Also because they're a safe wrapper for variables and jquery (like so:) jQuery(document).ready(function($) {
// all variables wrapped in function and $ is jQuery
}); |
|
Which means I would remove the outer function ;-) |
|
But the outer function is shorter, so in terms of page size optimization, it would make more sense to remove the inner one :) |
|
IMO we should still listen to domready, because someone could rely on the current behaviour. But there is a shorter version: Before: (function($) {
$(document).ready(function() {
// code…
});
})(jQuery);After: jQuery(function($) {
// code…
}); |
|
i think ausi's variant is the way to go. keeps the global clean and you get a save jQuery reference and are safe, if your script isnt at the end of the body. |
|
Is there a shorter version for MooTools as well? // Current wrapper
(function($) {
window.addEvent('domready', function() {
// …
});
})(document.id); |
|
Well you don't need the outer wrapper if you simply use document.id instead of $ in your code
|
|
I know. But that is actually not the answer to the question :) |
window.addEvent("domready", function() {
var $ = document.id;
}); |
|
Changed in contao/core-bundle@ef20adf. |
All functions are called at the bottom of the page, which means the document is already ready.