-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
286 lines (256 loc) · 8.64 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<title>Command.js</title>
<script src='slides.js'></script>
<!--
Uses Google HTML5 slides
URL: http://code.google.com/p/html5slides/
-->
</head>
<style>
section.slides.template-async article.biglogo {
background: white url(slides/images/async-logo.png) 50% 50% no-repeat;
}
p.smaller {
font-size: 20px;
line-height: 32px;
letter-spacing: 0;
}
.spacious {
margin-top:64px;
}
article pre {
max-height:560px;
overflow:auto;
}
article pre.half-margin-top {
margin-top:20px;
}
img.logo {
position:absolute;
top:20px;
right:20px;
}
</style>
<body style='display: none'>
<section class='slides layout-regular template-default'>
<article>
<h1>cmd.js</h1>
<p>Chris Newton</p>
<p class="smaller spacious">
<strong><a href="http://asyncjs.com/modular/">Async</a></strong> – 12th July, 2012<br />
<strong>Repo</strong> – <a href="https://github.com/premasagar/cmd.js">https://github.com/premasagar/cmd.js</a><br />
<strong>Slides</strong> – <a href="http://chrisnewtn.github.com/cmd-async-slides">http://chrisnewtn.github.com/cmd-async-slides</a><br />
<strong>Repo for slides</strong> – <a href="https://github.com/chrisnewtn/cmd-async-slides">https://github.com/chrisnewtn/cmd-async-slides</a><br />
<a rel="me" href="http://twitter.com/chrisnewtn">@chrisnewtn</a> ╱
<a rel="me" href="http://chrisnewtn.com">chrisnewtn.com</a>
<br />
<br />
<small>Use the <b>arrow keys</b> or <b>space</b> on your keyboard to navigate →</small>
</p>
</article>
<article>
<h2>What is cmd.js?</h2>
<div class="build">
<p>A lightweight, asynchronous flow controller / file loader.</p>
<p>Can load and execute a series of JavaScript files. Either in parallel or in sequence.</p>
</div>
</article>
<!--<article>
<h2>Regular Approach</h2>
<div>
<p>Markup script elements one after the other.</p>
<p>Scripts are loaded in sequence.</p>
<p>Scripts coupled with HTML.</p>
<p>Limited to no flow control.</p>
</div>
</article>-->
<!--<article>
<h3>Typical HTML page</h3>
<pre class="build"><span><html>
<head>
<!-- omitted -->
<script src="jquery.js"></script>
<script src="jquery-plugin-1.js"></script>
<script src="jquery-plugin-2.js"></script>
<script src="underscore.js"></script>
<script src="site-script.js"></script></span><span>
<!--[if lt IE 9]><script src="shiv.js"></script><![endif]--></span><span>
</head>
<body>
<!-- omitted -->
<script src="google-analytics.js"></script>
<script src="twitter-widget.js"></script>
<script src="flickr-widget.js"></script>
</body>
</html></span></pre>
</article>
<article>
<h2>Why use cmd.js?</h2>
<div class="build">
<h3>Bit more succinct...</h3>
<pre><span><html>
<head>
<!-- omitted -->
</head>
<body>
<!-- omitted -->
<script src="cmd.js"></script>
<script src="site-script.js"></script>
</body>
</html></span></pre></div>
</article>-->
<article>
<h3>cmd.js in action</h3>
<div class="build">
<div style="margin-top:40px">
<p>Load a single script <small>(remote or local)</small></p>
<pre class="half-margin-top">cmd('http://example.com/im-important.js');</pre>
</div>
<div>
<p>Load & execute scripts one after the other <small>(dependencies!)</small></p>
<pre class="half-margin-top">cmd('he-needs-me.js', 'i-need-him.js');</pre>
</div>
<div>
<p>Load scripts in parallel</p>
<pre class="half-margin-top">cmd(['i-dont-need-nothing.js', 'i-will-fire-when-ready.js']);</pre>
</div>
</div>
</article>
<article>
<h3>Callbacks</h3>
<div class="build">
<div style="margin-top:40px">
<p>Check if a script has loaded ok.</p>
<pre class="half-margin-top">cmd('prettify.js', function (loadedOk) {
if (loadedOk) prettyPrint();
});</pre>
</div>
<div>
<p>Add as many callbacks as you like.</p>
<pre class="half-margin-top">cmd(
'does-nothing-onload.js',
nowItDoes,
'also-does-nothing.js',
nowItDoesToo
);</pre>
</div>
</div>
</article>
<article>
<h3>What I use cmd.js to solve...</h3>
<pre class="build"><span><html>
<head>
<!-- omitted -->
<script src="jquery.js"></script>
<script src="jquery-plugin-1.js"></script>
<script src="jquery-plugin-2.js"></script>
<script src="underscore.js"></script>
<script src="site-script.js"></script></span><span>
<!--[if lt IE 9]><script src="shiv.js"></script><![endif]--></span><span>
</head>
<body>
<!-- omitted -->
<script src="google-analytics.js"></script>
<script src="twitter-widget.js"></script>
<script src="flickr-widget.js"></script>
</body>
</html></span></pre>
</article>
<article>
<h3>Cleaner and self contained</h3>
<pre>cmd(
'jquery.js',
[
'jquery-plugin-1.js',
'jquery-plugin-2.js',
'underscore.js'
],
'site-script.js'
);</pre>
<div class="build">
<p>Load jQuery first.</p>
<p>Load the plugins & Underscore in parallel.</p>
<p>Load site script last.</p>
</div>
</article>
<article>
<h3>Flow Control</h3>
<div class="build">
<div style="margin-top:40px">
<p>Minified or unminified?</p>
<pre class="half-margin-top">var ext = devMode ? '.js' : '.min.js';
cmd(
'site-script' + ext,
'another-script' + ext
);</pre>
</div>
<div>
<p>Load scripts based on user input.</p>
<pre class="half-margin-top">if (userAcceptsCookies) {
cmd('google-analytics.js');
}</pre>
</div>
</div>
</article>
<article>
<h3>Options</h3>
<div class="build">
<div style="margin-top:40px">
<p>Prepend a path to every script</p>
<pre class="half-margin-top">cmd(
'jquery.js',
[
'jquery-plugin-1.js',
'jquery-plugin-2.js'
],
{
path: '/js/vendor/jquery/'
}
);</pre>
</div>
</div>
</article>
<article>
<h3>Options</h3>
<div class="build">
<div style="margin-top:40px">
<p>Improved devmode <small>(preventing script caching)</small></p>
<pre class="half-margin-top">var ext = devMode ? '.js' : '.min.js';
cmd(
'site-script' + ext,
'another-script' + ext,
{
path: '/js/',
noCache: true
}
);</pre>
</div>
</div>
</article>
<article>
<h2>cmd.js is great for</h2>
<div class="build">
<p>Conditionally loading scripts.</p>
<p>Managing dependencies.</p>
<p>Ensuring scripts are being loaded.</p>
<p>Relying less on markup.</p>
</div>
</article>
<article>
<h1>Thank you.</h1>
<p>Chris Newton</p>
<p class="smaller spacious">
<strong><a href="http://asyncjs.com/modular/">Async</a></strong> – 12th July, 2012<br />
<strong>Repo</strong> – <a href="https://github.com/premasagar/cmd.js">https://github.com/premasagar/cmd.js</a><br />
<strong>Slides</strong> – <a href="http://chrisnewtn.github.com/cmd-async-slides">http://chrisnewtn.github.com/cmd-async-slides</a><br />
<strong>Repo for slides</strong> – <a href="https://github.com/chrisnewtn/cmd-async-slides">https://github.com/chrisnewtn/cmd-async-slides</a><br />
<a rel="me" href="http://twitter.com/chrisnewtn">@chrisnewtn</a> ╱
<a rel="me" href="http://chrisnewtn.com">chrisnewtn.com</a>
</p>
</article>
</section>
</body>
</html>