Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading jQuery, Underscore and Backbone using RequireJS 2.0.1 and shim
    text
    copied!<p>I am experimenting a little bit with RequireJS <strong><em>2.0.1</em></strong>. My goal is to load correctly jQuery, Underscore and Backbone. From the original <a href="http://requirejs.org/" rel="noreferrer">RequireJS doc</a> I discovered that the author J. Burke added (to this new release) a <a href="https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0#wiki-shim" rel="noreferrer">new config option called shim</a>.</p> <p>Then I wrote this stuff down here:</p> <p><code>index.html</code></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Testing time&lt;/title&gt; &lt;script data-main="scripts/main" src="scripts/require.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Testing time&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><code>scripts/main.js</code></p> <pre><code>requirejs.config({ shim: { 'libs/jquery': { exports: '$' }, 'libs/underscore': { exports: '_' }, 'libs/backbone': { deps: ['libs/underscore', 'libs/jquery'], exports: 'Backbone' } } }); define( ['libs/jquery', 'libs/underscore', 'libs/backbone'], function (jQueryLocal, underscoreLocal, backboneLocal) { console.log('local', jQueryLocal); console.log('local', underscoreLocal); console.log('local', backboneLocal); console.log('global', $); console.log('global', _); console.log('global', Backbone); } ); </code></pre> <p>Everything seems to work quite fine, but I have the feeling that I'm missing something, I know that there are <em>AMDed</em> version of jQuery and Underscore but if the setup is so simple I don't understand why I should use them.</p> <p>So, is this setup right or I'm missing something?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload