1 <!DOCTYPE html><html><head><title>Ext.Loader | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
2 <style type="text/css">.head-band { display: none; }
3 .header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
4 .doc-tab .members .member a.more { background-color: #efefef; }
5 </style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
6 </head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit
7 <a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">
12 origDocClass: 'Ext.Loader',
13 docClass: 'Ext.Loader',
27 <script type="text/javascript" src="../search.js"></script>
28 <!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
29 <script type="text/javascript" src="../class_tree.js"></script>
30 <script type="text/javascript" src="../class_doc.js"></script>
31 <script type="text/javascript">
32 req.source = 'Loader.html#Ext-Loader';
33 clsInfo = {"methods":["exclude","getConfig","getPath","onReady","require","setConfig","syncRequire"],"cfgs":["disableCaching","disableCachingParam","enabled","paths"],"properties":["history","setPath"],"events":[],"subclasses":[]};
34 Ext.onReady(function() {
35 Ext.create('Docs.classPanel');
37 </script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/Loader.html#Ext-Loader" target="_blank">Ext.Loader</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>Ext.Loader is the heart of the new dynamic dependency loading capability in <a href="Ext.html" rel="Ext" class="docClass">Ext</a> JS 4+. It is most commonly used
38 via the <a href="Ext.html#require" rel="Ext#require" class="docClass">Ext.require</a> shorthand. <a href="Ext.Loader.html" rel="Ext.Loader" class="docClass">Ext.Loader</a> supports both asynchronous and synchronous loading
39 approaches, and leverage their advantages for the best development flow. We'll discuss about the pros and cons of each approach:</p>
41 <h1>Asynchronous Loading</h1>
44 <li><p>Advantages:</p>
48 <li>No web server needed: you can run the application via the file system protocol (i.e: <code>file://path/to/your/index
50 <li>Best possible debugging experience: error messages come with the exact file name and line number</li>
53 <li><p>Disadvantages:</p>
56 <li>Dependencies need to be specified before-hand</li>
62 <h3>Method 1: Explicitly include what you need:</h3>
64 <pre class="prettyprint"><code>// Syntax
65 Ext.require({String/Array} expressions);
67 // Example: Single alias
68 Ext.require('widget.window');
70 // Example: Single class name
71 Ext.require('Ext.window.Window');
73 // Example: Multiple aliases / class names mix
74 Ext.require(['widget.window', 'layout.border', 'Ext.data.Connection']);
77 Ext.require(['widget.*', 'layout.*', 'Ext.data.*']);
80 <h3>Method 2: Explicitly exclude what you don't need:</h3>
82 <pre class="prettyprint"><code>// Syntax: Note that it must be in this chaining format.
83 Ext.exclude({String/Array} expressions)
84 .require({String/Array} expressions);
86 // Include everything except Ext.data.*
87 Ext.exclude('Ext.data.*').require('*');
89 // Include all widgets except widget.checkbox*,
90 // which will match widget.checkbox, widget.checkboxfield, widget.checkboxgroup, etc.
91 Ext.exclude('widget.checkbox*').require('widget.*');
94 <h1>Synchronous Loading on Demand</h1>
97 <li><p><em>Advantages:</em></p>
100 <li>There's no need to specify dependencies before-hand, which is always the convenience of including ext-all.js
104 <li><p><em>Disadvantages:</em></p>
107 <li>Not as good debugging experience since file name won't be shown (except in Firebug at the moment)</li>
108 <li>Must be from the same domain due to XHR restriction</li>
109 <li>Need a web server, same reason as above</li>
115 <p>There's one simple rule to follow: Instantiate everything with Ext.create instead of the <code>new</code> keyword</p>
117 <pre class="prettyprint"><code>Ext.create('widget.window', { ... }); // Instead of new Ext.window.Window({...});
119 Ext.create('Ext.window.Window', {}); // Same as above, using full class name instead of alias
121 Ext.widget('window', {}); // Same as above, all you need is the traditional `xtype`
124 <p>Behind the scene, <a href="Ext.ClassManager.html" rel="Ext.ClassManager" class="docClass">Ext.ClassManager</a> will automatically check whether the given class name / alias has already
125 existed on the page. If it's not, <a href="Ext.Loader.html" rel="Ext.Loader" class="docClass">Ext.Loader</a> will immediately switch itself to synchronous mode and automatic load the given
126 class and all its dependencies.</p>
128 <h1>Hybrid Loading - The Best of Both Worlds</h1>
130 <p>It has all the advantages combined from asynchronous and synchronous loading. The development flow is simple:</p>
132 <h3>Step 1: Start writing your application using synchronous approach. <a href="Ext.Loader.html" rel="Ext.Loader" class="docClass">Ext.Loader</a> will automatically fetch all</h3>
134 <p> dependencies on demand as they're needed during run-time. For example: ###</p>
136 <pre class="prettyprint"><code>Ext.onReady(function(){
137 var window = Ext.createWidget('window', {
144 title: 'Hello Dialog',
162 <h3>Step 2: Along the way, when you need better debugging ability, watch the console for warnings like these:</h3>
164 <pre class="prettyprint"><code>[Ext.Loader] Synchronously loading 'Ext.window.Window'; consider adding Ext.require('Ext.window.Window') before your application's code
166 [Ext.Loader] Synchronously loading 'Ext.layout.container.Border'; consider adding Ext.require('Ext.layout.container.Border') before your application's code
169 <p>Simply copy and paste the suggested code above <code>Ext.onReady</code>, i.e:</p>
171 <pre class="prettyprint"><code>Ext.require('Ext.window.Window');
172 Ext.require('Ext.layout.container.Border');
177 <p>Everything should now load via asynchronous mode.</p>
181 <p>It's important to note that dynamic loading should only be used during development on your local machines.
182 During production, all dependencies should be combined into one single JavaScript file. <a href="Ext.Loader.html" rel="Ext.Loader" class="docClass">Ext.Loader</a> makes
183 the whole process of transitioning from / to between development / maintenance and production as easy as
184 possible. Internally <a href="Ext.Loader.html#history" rel="Ext.Loader#history" class="docClass">Ext.Loader.history</a> maintains the list of all dependencies your application
185 needs in the exact loading sequence. It's as simple as concatenating all files in this array into one,
186 then include it on top of your application.</p>
188 <p>This process will be automated with Sencha Command, to be released and documented towards <a href="Ext.html" rel="Ext" class="docClass">Ext</a> JS 4 Final.</p>
189 <div class="members"><div class="m-cfgs"><div class="definedBy">Defined By</div><a name="configs"></a><h3 class="cfg p">Config Options</h3><h4 class="cfgGroup">Other Configs</h4><div id="config-disableCaching" class="member f ni"><a href="Ext.Loader.html#config-disableCaching" rel="config-disableCaching" class="expand more"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-cfg-disableCaching" class="viewSource">view source</a></div><a name="disableCaching"></a><a name="config-disableCaching"></a><a href="Ext.Loader.html#" rel="config-disableCaching" class="cls expand">disableCaching</a><span> : Boolean</span></div><div class="description"><div class="short"><p>Appends current timestamp to script files to prevent caching
191 </div><div class="long"><p>Appends current timestamp to script files to prevent caching
193 </div></div></div><div id="config-disableCachingParam" class="member ni"><a href="Ext.Loader.html#config-disableCachingParam" rel="config-disableCachingParam" class="expand more"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-cfg-disableCachingParam" class="viewSource">view source</a></div><a name="disableCachingParam"></a><a name="config-disableCachingParam"></a><a href="Ext.Loader.html#" rel="config-disableCachingParam" class="cls expand">disableCachingParam</a><span> : String</span></div><div class="description"><div class="short"><p>The get parameter name for the cache buster's timestamp.
194 Defaults to '_dc'</p>
195 </div><div class="long"><p>The get parameter name for the cache buster's timestamp.
196 Defaults to '_dc'</p>
197 </div></div></div><div id="config-enabled" class="member ni"><a href="Ext.Loader.html#config-enabled" rel="config-enabled" class="expand more"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-cfg-enabled" class="viewSource">view source</a></div><a name="enabled"></a><a name="config-enabled"></a><a href="Ext.Loader.html#" rel="config-enabled" class="cls expand">enabled</a><span> : Boolean</span></div><div class="description"><div class="short"><p>Whether or not to enable the dynamic dependency loading feature
198 Defaults to false</p>
199 </div><div class="long"><p>Whether or not to enable the dynamic dependency loading feature
200 Defaults to false</p>
201 </div></div></div><div id="config-paths" class="member ni"><a href="Ext.Loader.html#config-paths" rel="config-paths" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-cfg-paths" class="viewSource">view source</a></div><a name="paths"></a><a name="config-paths"></a><a href="Ext.Loader.html#" rel="config-paths" class="cls expand">paths</a><span> : Object</span></div><div class="description"><div class="short">The mapping from namespaces to file paths
204 'Ext': '.', // This is set by default, Ext.layout.container.Containe...</div><div class="long"><p>The mapping from namespaces to file paths</p>
207 'Ext': '.', // This is set by default, <a href="Ext.layout.container.Container.html" rel="Ext.layout.container.Container" class="docClass">Ext.layout.container.Container</a> will be
208 // loaded from ./layout/Container.js
210 'My': './src/my_own_folder' // My.layout.Container will be loaded from
211 // ./src/my_own_folder/layout/Container.js
215 <p>Note that all relative paths are relative to the current HTML document.
216 If not being specified, for example, <code>Other.awesome.Class</code>
217 will simply be loaded from <code>./Other/awesome/Class.js</code></p>
218 </div></div></div></div><div class="m-properties"><a name="properties"></a><div class="definedBy">Defined By</div><h3 class="prp p">Properties</h3><div id="property-history" class="member f ni"><a href="Ext.Loader.html#property-history" rel="property-history" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-property-history" class="viewSource">view source</a></div><a name="history"></a><a name="property-history"></a><a href="Ext.Loader.html#" rel="property-history" class="cls expand">history</a><span> : Array</span></div><div class="description"><div class="short">An array of class names to keep track of the dependency loading order.
219 This is not guaranteed to be the same everytim...</div><div class="long"><p>An array of class names to keep track of the dependency loading order.
220 This is not guaranteed to be the same everytime due to the asynchronous
221 nature of the Loader.</p>
222 </div></div></div><div id="property-setPath" class="member ni"><a href="Ext.Loader.html#property-setPath" rel="property-setPath" class="expand more"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-property-setPath" class="viewSource">view source</a></div><a name="setPath"></a><a name="property-setPath"></a><a href="Ext.Loader.html#" rel="property-setPath" class="cls expand">setPath</a><span> : Object</span></div><div class="description"><div class="short"><p>Sets the path of a namespace.
225 <pre><code>Ext.Loader.setPath('Ext', '.');
227 </div><div class="long"><p>Sets the path of a namespace.
230 <pre><code>Ext.Loader.setPath('Ext', '.');
232 </div></div></div></div><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-exclude" class="member f ni"><a href="Ext.Loader.html#method-exclude" rel="method-exclude" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-method-exclude" class="viewSource">view source</a></div><a name="exclude"></a><a name="method-exclude"></a><a href="Ext.Loader.html#" rel="method-exclude" class="cls expand">exclude</a>(
233 <span class="pre">Array excludes</span>)
234 : Object</div><div class="description"><div class="short">Explicitly exclude files from being loaded. Useful when used in conjunction with a broad include expression.
235 Can be c...</div><div class="long"><p>Explicitly exclude files from being loaded. Useful when used in conjunction with a broad include expression.
236 Can be chained with more <code>require</code> and <code>exclude</code> methods, eg:</p>
238 <pre><code>Ext.exclude('Ext.data.*').require('*');
240 Ext.exclude('widget.button*').require('widget.*');
242 <h3 class="pa">Parameters</h3><ul><li><span class="pre">excludes</span> : Array<div class="sub-desc">
243 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Object</span> <p>object contains <code>require</code> method for chaining</p>
244 </li></ul></div></div></div><div id="method-getConfig" class="member ni"><a href="Ext.Loader.html#method-getConfig" rel="method-getConfig" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-method-getConfig" class="viewSource">view source</a></div><a name="getConfig"></a><a name="method-getConfig"></a><a href="Ext.Loader.html#" rel="method-getConfig" class="cls expand">getConfig</a>(
245 <span class="pre">String name</span>)
246 : Object/Mixed</div><div class="description"><div class="short"><p>Get the config value corresponding to the specified name. If no name is given, will return the config object</p>
247 </div><div class="long"><p>Get the config value corresponding to the specified name. If no name is given, will return the config object</p>
248 <h3 class="pa">Parameters</h3><ul><li><span class="pre">name</span> : String<div class="sub-desc"><p>The config property name</p>
249 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Object/Mixed</span>
250 </li></ul></div></div></div><div id="method-getPath" class="member ni"><a href="Ext.Loader.html#method-getPath" rel="method-getPath" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-method-getPath" class="viewSource">view source</a></div><a name="getPath"></a><a name="method-getPath"></a><a href="Ext.Loader.html#" rel="method-getPath" class="cls expand">getPath</a>(
251 <span class="pre">String className</span>)
252 : String</div><div class="description"><div class="short">Translates a className to a file path by adding the
253 the proper prefix and converting the .'s to /'s. For example:
255 Ex...</div><div class="long"><p>Translates a className to a file path by adding the
256 the proper prefix and converting the .'s to /'s. For example:</p>
258 <pre><code>Ext.Loader.setPath('My', '/path/to/My');
260 alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/path/to/My/awesome/Class.js'
263 <p>Note that the deeper namespace levels, if explicitly set, are always resolved first. For example:</p>
265 <pre><code>Ext.Loader.setPath({
266 'My': '/path/to/lib',
267 'My.awesome': '/other/path/for/awesome/stuff',
268 'My.awesome.more': '/more/awesome/path'
271 alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/other/path/for/awesome/stuff/Class.js'
273 alert(Ext.Loader.getPath('My.awesome.more.Class')); // alerts '/more/awesome/path/Class.js'
275 alert(Ext.Loader.getPath('My.cool.Class')); // alerts '/path/to/lib/cool/Class.js'
277 alert(Ext.Loader.getPath('Unknown.strange.Stuff')); // alerts 'Unknown/strange/Stuff.js'
279 <h3 class="pa">Parameters</h3><ul><li><span class="pre">className</span> : String<div class="sub-desc">
280 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">String</span> <p>path</p>
281 </li></ul></div></div></div><div id="method-onReady" class="member ni"><a href="Ext.Loader.html#method-onReady" rel="method-onReady" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-method-onReady" class="viewSource">view source</a></div><a name="onReady"></a><a name="method-onReady"></a><a href="Ext.Loader.html#" rel="method-onReady" class="cls expand">onReady</a>(
282 <span class="pre">Function fn, Object scope, Boolean withDomReady, Object options</span>)
283 : void</div><div class="description"><div class="short"><p>Add a new listener to be executed when all required scripts are fully loaded</p>
284 </div><div class="long"><p>Add a new listener to be executed when all required scripts are fully loaded</p>
285 <h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The function callback to be executed</p>
286 </div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>The execution scope (<code>this</code>) of the callback function</p>
287 </div></li><li><span class="pre">withDomReady</span> : Boolean<div class="sub-desc"><p>Whether or not to wait for document dom ready as well</p>
288 </div></li><li><span class="pre">options</span> : Object<div class="sub-desc">
289 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>
290 </li></ul></div></div></div><div id="method-require" class="member ni"><a href="Ext.Loader.html#method-require" rel="method-require" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-method-require" class="viewSource">view source</a></div><a name="require"></a><a name="method-require"></a><a href="Ext.Loader.html#" rel="method-require" class="cls expand">require</a>(
291 <span class="pre">String/Array expressions, Function fn, Object scope, String/Array excludes</span>)
292 : void</div><div class="description"><div class="short">Loads all classes by the given names and all their direct dependencies; optionally executes the given callback functi...</div><div class="long"><p>Loads all classes by the given names and all their direct dependencies; optionally executes the given callback function when
293 finishes, within the optional scope. This method is aliased by <a href="Ext.html#require" rel="Ext#require" class="docClass">Ext.require</a> for convenience</p>
294 <h3 class="pa">Parameters</h3><ul><li><span class="pre">expressions</span> : String/Array<div class="sub-desc"><p>Can either be a string or an array of string</p>
295 </div></li><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>(Optional) The callback function</p>
296 </div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(Optional) The execution scope (<code>this</code>) of the callback function</p>
297 </div></li><li><span class="pre">excludes</span> : String/Array<div class="sub-desc"><p>(Optional) Classes to be excluded, useful when being used with expressions</p>
298 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>
299 </li></ul></div></div></div><div id="method-setConfig" class="member ni"><a href="Ext.Loader.html#method-setConfig" rel="method-setConfig" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-method-setConfig" class="viewSource">view source</a></div><a name="setConfig"></a><a name="method-setConfig"></a><a href="Ext.Loader.html#" rel="method-setConfig" class="cls expand">setConfig</a>(
300 <span class="pre">Object config, Object value</span>)
301 : Ext.Loader</div><div class="description"><div class="short">Set the configuration for the loader. This should be called right after ext-core.js
302 (or ext-core-debug.js) is include...</div><div class="long"><p>Set the configuration for the loader. This should be called right after ext-core.js
303 (or ext-core-debug.js) is included in the page, i.e:</p>
305 <pre><code><script type="text/javascript" src="ext-core-debug.js"></script>
306 <script type="text/javascript">
307 Ext.Loader.setConfig({
314 <script type="text/javascript">
317 Ext.onReady(function() {
318 // application code here
323 <p>Refer to <a href="Ext.Loader.html#configs" rel="Ext.Loader#configs" class="docClass">configs</a> for the list of possible properties</p>
324 <h3 class="pa">Parameters</h3><ul><li><span class="pre">config</span> : Object<div class="sub-desc"><p>The config object to override the default values in <a href="Ext.Loader.html#config" rel="Ext.Loader#config" class="docClass">config</a></p>
325 </div></li><li><span class="pre">value</span> : Object<div class="sub-desc">
326 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Ext.Loader</span> <p>this</p>
327 </li></ul></div></div></div><div id="method-syncRequire" class="member ni"><a href="Ext.Loader.html#method-syncRequire" rel="method-syncRequire" class="expand more ar"><span> </span></a><div class="title"><div class="meta"><a href="Ext.Loader.html" class="definedIn docClass">Ext.Loader</a><br/><a href="../source/Loader.html#Ext-Loader-method-syncRequire" class="viewSource">view source</a></div><a name="syncRequire"></a><a name="method-syncRequire"></a><a href="Ext.Loader.html#" rel="method-syncRequire" class="cls expand">syncRequire</a>(
328 <span class="pre">String/Array expressions, Function fn, Object scope, String/Array excludes</span>)
329 : void</div><div class="description"><div class="short">Synchronously loads all classes by the given names and all their direct dependencies; optionally executes the given c...</div><div class="long"><p>Synchronously loads all classes by the given names and all their direct dependencies; optionally executes the given callback function when finishes, within the optional scope. This method is aliased by <a href="Ext.html#syncRequire" rel="Ext#syncRequire" class="docClass">Ext.syncRequire</a> for convenience</p>
330 <h3 class="pa">Parameters</h3><ul><li><span class="pre">expressions</span> : String/Array<div class="sub-desc"><p>Can either be a string or an array of string</p>
331 </div></li><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>(Optional) The callback function</p>
332 </div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(Optional) The execution scope (<code>this</code>) of the callback function</p>
333 </div></li><li><span class="pre">excludes</span> : String/Array<div class="sub-desc"><p>(Optional) Classes to be excluded, useful when being used with expressions</p>
334 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>
335 </li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>