- Building Single:page Web Apps with Meteor
- Fabian Vogelsteller
- 363字
- 2021-08-06 19:29:36
Meteor's folder conventions and loading order
Though Meteor doesn't impose restrictions concerning our folder names or structure, there are naming conventions that help Meteor's build process to determine the order in which the files need to be loaded.
The following table describes the folder and their specific loading order:

The following table describes filenames that have created a specific loading order:

So, we see that Meteor gathers all files except the ones inside public
, private
, and tests
.
Additionally, files are always loaded in the alphabetical order, and files in subfolders are loaded before the ones in parent folders.
If we have files outside the client
or server
folder and want to determine where the code should be executed, we can use the following variables:
if(Meteor.isClient) { // Some code executed on the client } if(Meteor.isServer) { // Some code executed on the server. }
We also see that code inside a main.*
file is loaded last. To make sure a specific code only loads when all files are loaded and the DOM on the client is ready, we can use the Meteor's startup()
function:
Meteor.startup(function(){ /* This code runs on the client when the DOM is ready, and on the server when the server process is finished starting. */ });
Loading assets on the server
To load files from inside the private
folder on the server, we can use the Assets
API as follows:
Assets.getText(assetPath, [asyncCallback]); // or Assets.getBinary(assetPath, [asyncCallback])
Here, assetPath
is a file path relative to the private
folder, for example, 'subfolder/data.txt'
.
If we provide a callback function as the second parameter, the Assets()
method will run asynchronously. So, we have two ways of retrieving the content of an assets file:
// Synchronously var myData = Assets.getText('data.txt'); // Or asynchronously Assets.getText('data.txt', function(error, result){ // Do somthing with the result. // If the error parameter is not NULL, something went wrong });
Now that we understand Meteor's basic folder structure, let's take a brief look at the Meteor's command-line tool.
- Learn TypeScript 3 by Building Web Applications
- Visual FoxPro程序設計教程(第3版)
- 微服務設計原理與架構
- 深入分布式緩存:從原理到實踐
- Java編程的邏輯
- 深入淺出React和Redux
- 劍指大數據:企業級數據倉庫項目實戰(在線教育版)
- Android移動開發案例教程:基于Android Studio開發環境
- Unity 2018 Augmented Reality Projects
- Practical GIS
- 分布式數據庫HBase案例教程
- 高質量程序設計指南:C++/C語言
- Visual C#(學習筆記)
- Mastering Machine Learning with scikit-learn
- 數據庫技術及應用教程上機指導與習題(第2版)