Require.js Error: Load timeout for modules: backbone,jquerymobile

Require.js has a Config option called waitSeconds. This may help. RequireJS waitSeconds Here’s an example where waitSeconds is used: requirejs.config({ baseUrl: “scripts”, enforceDefine: true, urlArgs: “bust=” + (new Date()).getTime(), waitSeconds: 200, paths: { “jquery”: “libs/jquery-1.8.3”, “underscore”: “libs/underscore”, “backbone”: “libs/backbone” }, shim: { “underscore”: { deps: [], exports: “_” }, “backbone”: { deps: [“jquery”, “underscore”], exports: … Read more

Dynamic require in RequireJS, getting “Module name has not been loaded yet for context” error?

The limitation relates to the simplified CommonJS syntax vs. the normal callback syntax: http://requirejs.org/docs/whyamd.html#commonjscompat https://github.com/jrburke/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define Loading a module is inherently an asynchronous process due to the unknown timing of downloading it. However, RequireJS in emulation of the server-side CommonJS spec tries to give you a simplified syntax. When you do something like this: var foomodule … Read more

Understanding when and how to use Require.JS

define() should only be used to define a module. For the above example, where a piece of code should be dynamically loaded, using require() is more appropriate: functionA.js functionA(){ require([‘functionC’],function(functionC){ //use funcC in here to call functionC }); } Some notes: require([]) is asynchronous, so if the caller of functionA is expecting a return value … Read more

Getting requirejs to work with Jasmine

I managed to get this working with some trial and error. The main issue was that when you write specs it isn’t a require that you want to create, you want to use define: Original: require([“/lib/jasmine/src/notepad”], function (notepad) { describe(“returns titles”, function() { expect(notepad.noteTitles()).toEqual(“pick up the kids get milk”); }); }); Working: define([“lib/jasmine/src/notepad”], function (notepad) … Read more

RequireJS: Loading modules including templates and CSS [closed]

You can specify the template as a dependency using the text! module like you have shown. I do this with Mustache Templates. However Require.js does not explicitly support css files. Here is the official explanation, it’s explained pretty well: http://requirejs.org/docs/faq-advanced.html#css Edit: Feb 2012. Templates such as handlebars can also be precompiled and included just like … Read more

Using reactjs with requirejs

So I figured it out myself. I got the necessary files and instructions from this repo: jsx-requirejs-plugin. Once I had jsx plugin and modified version of JSXTransformer, I changed my code as instructed in the repository : require.config({ // … paths: { “react”: “path/to/react”, “JSXTransformer”: “path/to/JSXTransformer”, “jsx”: “path/to/jsx plugin” … } // … }); Then, … Read more

Optimizing JS from WebJars using sbt-rjs in a Play 2.3.x app

I am using Play 2.4.3. Added addSbtPlugin(“com.typesafe.sbt” % “sbt-rjs” % “1.0.7”) to plugins.sbt // rjs = RequireJS, uglifies, shrinks to one file, replaces WebJars with CDN client accepts them pipelineStages := Seq(rjs, digest, gzip) This in my build.sbt does all the shrinking work etc. to bower JS, and webjars.