curl.js 0.8.4 has been released

100 views
Skip to first unread message

unscriptable

unread,
Oct 17, 2013, 9:25:25 AM10/17/13
to cuj...@googlegroups.com
curl.js 0.8.4 introduces a new feature: bootstrapping via HTML attribute!

If you're familiar with RequireJS's `data-main` feature, then you're already familiar with the concept.  In short, a special HTML attribute tells curl.js where the bootstrap script (aka "run.js") can be found.  All of the information needed to configure and start the application is inside the run.js file.

So, why not use `data-main` like other AMD loaders?  

curl.js looks for the HTML attribute `data-curl-run` rather than `data-main` for three important reasons:

1. RequireJS (and other AMD loaders) don't clean up `data-main` after using it.  Subsequent loaders on the page could accidentally use it again!
2. curl.js allows more than one run.js file to be specified in the attribute.  This feature is designed to allow you to quickly toggle between a standalone run.js and a bundle file without changing the HTML source.
3. The W3C highly recommends that `data-*` attributes be namespaced, so all curl-specific attributes should start with `data-curl-`.

More information is on the wiki.

voltron

unread,
Mar 27, 2014, 2:54:23 AM3/27/14
to cuj...@googlegroups.com
Nice! Just in time for a project I'm working on that uses require.js. I still have a question though, how can I use curl as a drop in replacement for require.js without the need of searching and replacing require() calls? Thanks 

Gabri elle

unread,
Mar 27, 2014, 2:09:16 PM3/27/14
to
Hi John,

a small comment on terminology: w3c does not recommend data-* attributes to be namespaced. In fact, w3c even defines custom data attributes (data-*) as being in no namespace (Cf. http://www.w3.org/html/wg/drafts/html/master/single-page.html#attr-data-*) - hence you can get its value by getAttribute() rather than getAttributeNS().
 
However, it does recommend indeed libraries to append their name to the attribute name (as you have done).

Cheers

unscriptable

unread,
Mar 27, 2014, 4:24:45 PM3/27/14
to cuj...@googlegroups.com
Hey Gabri,

Yes, definitely a terminology problem on my part!  I was using the term "namespace" in a non-expert manner.  Here's a sentence in the 2nd-to-last paragraph from the W3C section you linked that explains what I mean:

Authors of libraries that are reused by many authors are encouraged to include their name in the attribute names, to reduce the risk of clashes.

Thus, the "-curl" in data-curl-run.  :)

Regards,

-- John

unscriptable

unread,
Mar 27, 2014, 4:30:07 PM3/27/14
to cuj...@googlegroups.com
Hey voltron,

You should only have to replace one (or perhaps a very few) calls to global `requirejs()`.  The calls to `require()` in your modules should be using the "local require", not the global one!  The global `require` is an unfortunate anti-pattern in AMD.  I hope you weren't lured into using it.  

If you think you are using the global `require`, then please paste a sample module and I'll show you how to fix it. Sound good?

-- John
Reply all
Reply to author
Forward
0 new messages