Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  184] [ 7]  / answers: 1 / hits: 30519  / 12 Years ago, sun, march 18, 2012, 12:00:00

I've been using RequireJS for dependency management and must say that I love it - JavaScript has really matured recently.



However, one thing I cannot figure out is this: When using the optimizer to bundle all my JavaScript modules into one file, how can I keep loading some thirt party scripts (such as jquery) from an external CDN URL instead of having to bundle it with my application code?


More From » cdn

 Answers
101

This will load jQuery from a CDN:



<script src=http://requirejs.org/docs/release/2.1.5/comments/require.js></script>
<script type=text/javascript>
require.config({
paths: {
jquery: https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min
},
waitSeconds: 40
});
</script>

<div id=message>hello</div>

<script type=text/javascript>
require( [jquery],
function ($) {
alert($.fn.jquery + n + $(#message).text());
}
);
</script>


Fiddle Here.



This page from the requirejs docs shows how to eliminate a path from the optimised build. Basically use the empty: scheme. Excerpt here:



node ../../r.js -o name=main out=main-built.js baseUrl=. paths.jquery=empty:

[#86766] Friday, March 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quentinaveryb

Total Points: 102
Total Questions: 100
Total Answers: 93

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
quentinaveryb questions
Thu, Aug 6, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;