Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jquery UI with require.js and CDN

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.

like image 248
user1323136 Avatar asked Dec 19 '25 23:12

user1323136


2 Answers

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:"
}
like image 158
jevakallio Avatar answered Dec 24 '25 11:12

jevakallio


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.

like image 22
John Whitley Avatar answered Dec 24 '25 09:12

John Whitley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!