jensarps / AMD-feature

A loader plugin for AMD loaders
Other
161 stars 10 forks source link

example request: loading a JSON poly-fill only when required #2

Closed jokeyrhyme closed 11 years ago

jokeyrhyme commented 11 years ago

Love the plugin so far, but I am not quite sure how to use it to conditionally load a JSON poly-fill only in older browsers that don't have a built-in JSON global object.

Any hints and tips in getting this plugin to:

Cheers!

jensarps commented 11 years ago

@jokeyrhyme Thanks for the comment!

Right now, the only way to achieve this would be to create a no-op module that just returns the built-in JSON object. This is kinda unfortunate, as it triggers an unnecessary HTTP request.

However, it should be quite possible to add both kinds of functionality to the plugin itself – and as it sounds like a really useful addition, I'll give it a shot these days.

Thanks again!

jensarps commented 11 years ago

There it is :)

You now have a module property in the implementation map that allows you to directly point to an object.

See https://github.com/jensarps/AMD-feature/blob/master/README.md#direct-loading and the example code in https://github.com/jensarps/AMD-feature/tree/master/examples/direct-load

As for the no-op thing – you could just use the module property and put null or '' or anything in there to get no-op behavior.

Thanks again for the suggestion!