3

I am trying to use requirejs to load jqueryui with a CDN, this is my config:

paths:
 jqueryui: "http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"

shim:
 jqueryui:
   deps: ['jquery']

And now in my main module i just use require['jqueryui'], pretty much the standard way, everything else loads great from my private CDN, but the requirejs tries to load the jqueryui from the private CDN too, it seems to think that jqueryui is a local module. Not sure what is wrong. Also, i am using requirejs-rails gem as the wrapper for require.js.

6
  • Not sure, but i think you have to drop the '.js' in the jqueryui path. Commented Jan 7, 2013 at 21:08
  • Have tried with and without '.js', its kind of mixed documentation regarding that on requirejs-rails page and the actual requirejs documentation. The problem persists. Thanks though. Commented Jan 7, 2013 at 21:19
  • Strange, here I load everything from different CDN's, and no problem. What the path to jquery? "private.cdn/path/jquery.min.js"? Commented Jan 7, 2013 at 21:26
  • 1
    Is the problem occurring only in catenated/minified r.js builds by any chance? Commented Jan 7, 2013 at 21:36
  • @fencliff yes, it seems to work great in development, its only when i compile the layered build in production that i see a problem, is this a known problem? Commented Jan 8, 2013 at 2:50

2 Answers 2

3

When you run the RequireJS optimizer (r.js) on projects which have remote module references such as CDN content, you should use the empty: scheme in the build config.

From the documentation:

You may have a script you want to load from a Content Delivery Network (CDN) or any other server on a different domain. [...] However, it is more likely that you do not want to include that resource in the build. If the script does not have any dependencies, or you do not want to include its dependencies or will be including them in another way, then you can use the special 'empty:' scheme in the paths config to just skip the file when doing an optimization.

So try specifying in your build profile:

paths: {
    jqueryui: "empty:"
}
Sign up to request clarification or add additional context in comments.

5 Comments

thanks for this!, i am using requirejs-rails gem, it expects a yml file configuration that it translates to the the js config options. According to their docs, it is supposed to emit an "empty:", anytime you put in a url in the paths, but i am guessing its not, the gem was recently updated, i am just going to try older versions. But yes you are right here, its the build thats the issue.
Just confirmed it, the older version of the gem works fine! its the gem issue, will open a bug for the gem.
Not really understanding this. If you are not putting jQueryUI's url in the paths, where should you put it? How would your app then now where to fetch it, if there is just 'empty'?
Think I finally understood. When you say 'build profile', you mean some external file that you use when running 'node r.js', right? I thought you meant changing the application code to say "empty", but you are merely specifying an override! Am I right?
@oligofren yes that's correct. When you run the r.js optimizer, you can specify options either via command line or specifying a "build profile" which is simply a javascript file that calls require.config. See: requirejs.org/docs/optimization.html#wholeproject
1

Author of requirejs-rails here. This appears to be is a regression in r.js, which should automatically substitute empty: for CDN URLs in the configuration. requirejs-rails' explicit substitution of empty: was removed when jrburke/r.js#163 was released in r.js 2.0 and later.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.