Skip to content

24 ways to impress your friends

Vote down?

TVD

Great article Rich! I’m a huge fan of your work on Dribble.

Quite often document.write() gets a bad rap. But, to be fair, the issue isn’t using document.write() to write content to the DOM.

The overarching issue is should we use document.write() to load cross-domain scripts (or any scripts for that matter)? I believe we can all agree the answer is no.

Using a Callback approach is novel indeed, but what I really like about it is its unobtrusive foundation and the control it places in the hands of the developer.

Today, widgets like The Deck answer the “what”, “where”, “when” and “how” of injected content. Using a predefined callback puts the “where” and “when” concerns back in the hands of the developer – where they belong!

With a 50/50 split, and the right concerns in the right hands, surely this is a win/win for both parties.

How would a Callback approach compare to loading The Deck’s script asynchronously?

Asynchronous Loading Example:

(function(id) {

var s = document.createElement(‘SCRIPT’), s1 = document.getElementsByTagName(‘SCRIPT’) [0];

s.type = ‘text/javascript’;

s.async = true;

s.src = ‘http://widgetjonesdiary.com/punoftheday.js?id=’ + id;

s1.parentNode.insertBefore(s, s1);
})(“24ways”);

Love the approach! Take Care!