cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

(Analytics, Remarketing tag and now) Facebook #251

Closed szepeviktor closed 10 years ago

szepeviktor commented 10 years ago

https://developers.facebook.com/docs/javascript/howto/requirejs says nice things about AMD:

require.config({
  shim: {
    'facebook' : {
      export: 'FB'
    }
  },
  paths: {
    'facebook': '//connect.facebook.net/en_US/all'
  }
})
require(['fb']);

Maybe curl(['js!facebook!exports=window.FB']); ?

unscriptable commented 10 years ago

How about this?

curl.config({
  paths: {
    facebook: {
      location: '//connect.facebook.net/en_US/all',
      config: { loader: 'curl/loader/legacy', exports: 'FB' }
    }
  }
});
curl(['facebook']);
unscriptable commented 10 years ago

I don't understand the Analytics and Remarketing bits in the title. What do you mean, @szepeviktor?

szepeviktor commented 10 years ago

this https://github.com/cujojs/curl/issues/241 and https://github.com/krux/postscribe/ which hijacks document.write of Remarketing tag script (this is my latest finding) And this is the AMD issue https://github.com/krux/postscribe/issues/37

szepeviktor commented 10 years ago

What is the the difference between the outcome of js! and loader/legacy?

unscriptable commented 10 years ago

The legacy loader lets you reference a non-modular script as if it were a module:

// nice. looks like other modules. also: I think more like ES6 will be
define(['facebook'], function (fb) { /* ... */ });

rather than:

// kinda ugly and not cross-loader :(
define(['js!facebook!exports=FB'], function (fb) { /* ... */ });
szepeviktor commented 10 years ago

Thank you very much.

szepeviktor commented 10 years ago

Excuse me for asking. How can I detect wheather a js! script has already started loading? (to avoid loading it twice)

unscriptable commented 10 years ago

Hey Szépe,

In application code, you shouldn't need to detect whether a script is already loading. if you're using the js! plugin, you must ensure that any options, such as !order or !exports=…, are the same or you may see double downloads. If the options and the url are the same, the file will only be downloaded once. The legacy loader should never download more than once.

If you are building a curl shim or curl loader and want to detect if curl is already handling a url, you can use curl's internal API to check if there is a promise in the cache. Let me know if you need more details about creating a curl shim or loader!

-- John