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
});
}
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
});
}
Share
Improve this question
edited Jul 20, 2014 at 14:15
Benjamin Crouzier
41.9k48 gold badges177 silver badges239 bronze badges
asked Jul 27, 2012 at 2:36
crapthingscrapthings
2,4853 gold badges21 silver badges33 bronze badges
2 Answers
Reset to default 14As 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 $
.)
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)