From a5bdf481dfece9ebc57107d71be478f9b48cbd1e Mon Sep 17 00:00:00 2001 From: Daniel Li Date: Sat, 17 Jan 2015 20:26:11 +0800 Subject: [PATCH] Clarified load order in docs. Fixes #3431 --- docs/client/full-api/concepts.html | 53 +++++++++++++++++------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/docs/client/full-api/concepts.html b/docs/client/full-api/concepts.html index b76337afb4..8cbfd45206 100644 --- a/docs/client/full-api/concepts.html +++ b/docs/client/full-api/concepts.html @@ -185,34 +185,41 @@ in a real app could go. ### File Load Order -It is best to write your application in such a way that it is insensitive to the -order in which files are loaded, for example by using -[Meteor.startup](#meteor_startup), or by moving load order sensitive code into -[packages](#usingpackages), which can explicitly control both the load order of -their contents and their load order with respect to other packages. However -sometimes load order dependencies in your application are unavoidable. +It is best to write your application in such a way that it is insensitive to +the order in which files are loaded, for example by using [Meteor.startup](#meteor_startup), +or by moving load order sensitive code into [packages](#usingpackages), +which can explicitly control both the load order of their contents and their +load order with respect to other packages. However, sometimes load order +dependencies in your application are unavoidable. -When not using special filenames and directories: +There are several load ordering rules. They are *applied sequentially* to all +applicable files in the application, in the priority given below: -- Files in subdirectories are loaded before files in parent directories, so that -files in the deepest subdirectory are loaded first, and files in the root -directory are loaded last. - Within a directory, files are loaded in -alphabetical order by filename. +1. HTML template files are *always* loaded before everything else +2. Files beginning with `main.` are loaded last +3. Files inside *any* `/lib/` directory are loaded next +4. Files with deeper paths are loaded next +5. Files are then loaded in alphabetical order of the entire path -Below is a complete list of special file and directory names that control file -load order: - -- **lib** - - After sorting as described above, all files under directories named `lib` - are moved before everything else, preserving their order. - -- **main.*** - - All files that match `main.*` are moved after everything else, preserving - their order. +```js +nav.html +main.html +/client/lib/methods.js +/client/lib/styles.js +/lib/feature/styles.js +/lib/collections.js +/client/main.js +``` +For example, the files above are arranged in the correct load order. +`main.html` is loaded second because HTML templates are always loaded first, +even if it begins with `main.`, since rule 1 has priority over rule 2. +However, it will be loaded after `nav.html` because rule 2 has priority over +rule 5. +`/client/lib/styles.js` and `/lib/feature/styles.js` have identical load order +up to rule 4, however, since `client` comes before `lib`alphabetically, +it will be loaded first. ### Organizing Your Project