How to get data from database before any client-side code loaded?


When I try to fetch a client-side collection(which is basically the language setting) before everything else loaded. But I’m getting an iron:router error.

Probably I’m making a silly mistake about the loading order of a Meteor App but I couldn’t resolve the issue for two days.

In client/lib/_translations.js:

translations = {
    Visits: {
        en_US: "Visits",
        en_GB: "Visits",
        tr_TR: "Ziyaretler"
    "Language": {
        en_US: "Language",
        en_GB: "Language",
        tr_TR: "Dil"

selectedLanguage = "en_US";

Which is OK. But when I try to pull from database:

selectedLanguage = settings.findOne().language;

It’s giving me “iron:router Organize your Meteor application.” error. Also I did not understand the reason why iron:router giving me this error.

What I’m trying to do is defining a global variable(selectedLanguage) before any client side code loaded.

You can get the whole project from here.


Earliest fetch can be achieved in the callback of Meteor.subscribe() like:

Meteor.subscribe('settings', function() {
    selectedLanguage = settings.findOne().language;


If you are doing tranlations, I would look at using universe:i18n