1

In Meteor application's client folder I created js file which manipulates my template (client/index.html). It works fine when I run application locally in a browser. But when I deploy it to mobile phone my script does not work. Then I added console.log statements to my template and script and found that load order is different. In local browser it prints:

loading template
loading javascript

But in mobile phone it prints other way around:

loading javascript
loading template

Meteor documentation states that "HTML template files are always loaded before everything else". So why it is not true when I deploy my application to mobile phone?

MantasG
  • 223
  • 1
  • 2
  • 12

1 Answers1

0

You can change the order things are loaded by moving things around, and putting some files in folders to make them load later, ie behind the ones that you want first.

The way Meteor does this automatic loading is great until you hit a problem (like this one), and with some finessing you can get things to work again.

The recommended practice now is to not use the eager loading, but to explicitly load each module, and then you get control of the loading order. Part of this is to put your files in the /imports folder (or sub-folders), and explicitly load them with import statements. You put one file in /server, which is a top level file, and do the same with /client to load all the client files.

Depending on the size of your app it may mean some work, but it brings your code into line with the way files are imported in the rest of the javascript ecosystem.

Mikkel
  • 7,693
  • 3
  • 17
  • 31