Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Meteor.startup() or $(function() {})

Do they do the same thing ?

Which one should I use inside client?

if ( Meteor.is_client ) {
    Meteor.startup(function () {
        // my code here
    });
}

or

if ( Meteor.is_client ) {
    $(function() {
        // my code here
    });
}
like image 215
crapthings Avatar asked Jul 27 '12 02:07

crapthings


2 Answers

As far as I can tell, Meteor.startup (on the client) is very similar to jQuery's $ function. The main advantage of using it is that it's the same API on client and server, so if you want to write startup code in files that are run on both client and server, Meteor.startup will just work. (Also, I personally find Meteor.startup to be easier to read and more self-documenting than $.)

like image 133
David Glasser Avatar answered Sep 23 '22 08:09

David Glasser


I just ran into an issue that $ was called before template rendering so I hade to use Meteor.startup

So I'd say that if you need to work with DOM elements you have to use Meteor.startup (I used it for the jQuery File Upload plugin)

like image 34
Julien Avatar answered Sep 24 '22 08:09

Julien