Resolving remote or cdn urls?

Is there an existing way to resolve a remote url? Such as:

require(['http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'], function(jquery) {
  $('body').html('It works!')
})

If not, I was going to attempt to write a plugin for it. Where it just bundles a call to asynchronously load the remote resource. Just wanted to check to make sure a solution doesn’t already exist. Thanks!

Author: Fantashit

7 thoughts on “Resolving remote or cdn urls?

  1. see #150

    var $script = require("scriptjs");
    $script("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js", function() {
      $('body').html('It works!')
    });
  2. @jlianphoto what? I don’t know if I’m getting what you meant, how doesn’t it, if it is working with commonjs’ require? Why wouldn’t it? Looking at the repo, it seems there’s a commit 6 years ago (on Makefile), commited as – AMD support… anyway…

    Even though, my question was, if, is there a better approach nowadays, instead of scriptjs?

  3. @jlianphoto what? I don’t know if I’m getting what you meant, how doesn’t it, if it is working with commonjs’ require? Why wouldn’t it? Looking at the repo, it seems there’s a commit 6 years ago (on Makefile), commited as – AMD support… anyway…

    Even though, my question was, if, is there a better approach nowadays, instead of scriptjs?

    This should interest you.
    This is an updated library.

    LoadJS is based on the excellent $script library by Dustin Diaz. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 789 bytes (minified + gzipped).

    https://github.com/muicss/loadjs

  4. Can we use just a native dynamic import for such cases?

    import( /* webpackIgnore: true */ 'http://remote-resource').then(....);
    

Comments are closed.