0

I am trying to have folder structure given here.

The difference is I am using all latest development version of these libraries. However, they are not correctly being uploaded, even jquery. I could not understand what by AMD compatible mean.

I simply downloaded those libraries. Does it mean they are not AMD compatible? Is there a separate AMD compatible version of those libraries?. Do we need to use shim config to load non AMD compatible?.

I am afraid to use shim because require.js official documentation says it is not recommended.

2 Answers 2

2

@kryger's right that jQuery is AMD-compatible and there's nothing wrong with shimming non-AMD modules.

AMD-compatible just means that the module adheres to the AMD specification; hence it exports its functionality. For example:

define(['jquery', 'underscore'], function ($, _) {
    // function body
});

So in the function body, above:

  • you can access jQuery via the $ argument; but
  • underscore doesn't export itself for AMD, so the _ argument will be undefined.

Some AMD-compatible modules (e.g. jQuery) also work 'standalone', such as in an HTML <script> tag, where they will export to the global namespace (e.g. window.$).

I think jQuery still exports the global $ when you load it via an AMD loader, so you could just load jQuery once at your entry-point / when it is first needed and always access the global $ (rather than defining a $ argument).

Also, if you use jQuery plugins (which modify the global one) it can all get a bit confusing!

Sign up to request clarification or add additional context in comments.

Comments

1

I couldn't find any mention of shim being "not recommended" in the documentation; I wouldn't be too worried about it. It's a well-tested and increasingly popular way of bridging non-AMD-compliant libraries with RequireJS (previously the only way to do this was was to build a dedicated AMD version wrapped in the define call; that puts extra effort on the library maintainers).

If by "latest development version" you mean jQuery's Pre-Release Builds, it looks like it does support AMD (have a look at the pre-release section of the download page, scroll down to very bottom the source code file: you'll see code relating to AMD)

Backbone and underscore need to be shimmed in any case since they are AMD-agnostic, so there's no escaping from it (these two particular libraries are even used in shim config option documentation example, so you can just reuse that).

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.