When you make a project with the Meteor framework, it packages all the files together, but there doesn't seem to be a way to explicitly say "I want this file to be loaded before that one".
Let's say, for example, I have 2 javascript files: foo.js
and bar.js
.
The file bar.js
is actually containing code depending one the one inside foo.js
but Meteor is loading bar.js
before foo.js
, breaking the project.
require('./bar')
inside foo.js
<script>
tag pointing to foo.js
and another, after, pointing to bar.js
, in order to load the files in the correct order.How can we do that in Meteor?
If I'm understanding your question I think you're asking if it matters where in a file a function/method is defined, and the answer is no, you can define them anywhere in a single source file. The JavaScript parser will read in all symbols before trying to run the code.
To avoid multiple server requests, group your JavaScript files into one. Whatever you use for performance, try to minify JavaScript to improve the load time of the web page. If you are using single page application, then group all the scripts in a single file.
According to the Meteor documentation, files are currently loaded in this order:
Source: http://docs.meteor.com/#structuringyourapp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With