crapthings
crapthings

Reputation: 2485

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
    });
}

Upvotes: 15

Views: 9461

Answers (2)

Julien
Julien

Reputation: 9432

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)

Upvotes: 5

David Glasser
David Glasser

Reputation: 1468

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 $.)

Upvotes: 14

Related Questions