Finally, we need to call our init method when the document has finished loading. We do this by
applying an onload handler to the window object using addEvent:
/* initiate when the window has finished loading */
deliciousbadge.addEvent(window, 'load', deliciousbadge.init, false);
this script to your document simply by including at the top of your page a script element that
points to it. Just add a link to your own del.icio.us bookmarks that has the correct id, and the script
will do the rest! You can then make use of the ids to style the final result to your liking.
Calling for Server Backup
While the script we’ve just walked through creates a nifty little badge that will make your personal
site the envy of all your friends, there are occasions when you may want to implement a server-side
component that acts as a backup, should the client-side script fail. There are several reasons why
this can be a good idea:
Some APIs have rate limits, which dictate how many times per day you can call them. With a
server-side control you could store a cached copy of the external site’s data on your server and
only update it every few hours. This type of rate limiting usually only applies to APIs that require
a developer key.
If you’re dealing with a flaky API, you could store a copy of the data on your server each time
you query the third-party server. This cache can then be used as a backup—the data may not be
the most up to date, but at least you can be sure that your badge won’t break.
You can use a server-side component to pare the amount of data you retrieve down to the absolute
minimum, or to convert any data that’ s not in an easily manageable format into something more
digestible (like JSON).