It's pretty common these days to integrate widgets from several sources and aggregate them to your website.
In an ideal world you would simply parse your api response(an xml for example) and display it on your page.
While this doesn't include javascript widgets, these are some thoughts I gathered which may prove useful:
Always cacheCache the api response or the page fragment being rendered, otherwise your website will load slowly. It's not only about speed, but most api providers request this. So while you may get away without caching for a while, you may find your self banned after a traffic spike.
Make sure you write the code efficientWhile I consider this a newbies tip, I wouldn't had mentioned it if I had not encounterd it.
Never do this:
foreach(getFeedContent() as $entry) {
// display code
}
At each iteration the server would try to fetch and parse the feed.
So at a basic level you should have something in the lines of:
$entries = getFeedContent();
foreach($entries as $entry) {
// display code
}
Don't assume that you'll get a valid responseSometimes your provider may send you an invalid/blank response. If this is happening often make sure you check its integrity before caching it. This way you won't be stuck with an empty section in your page for the period the page has been cached. Additionally make sure this check is done inside your actual code as well so that you don't display the affected section or at least have it degrade to a nice custom error message.
Protect your layoutIf you have images inside your response and intend to use them, scale them to a predefined maximum size and store them on your server. If they always have fixed proportions make sure that they actually stay fixed by adding the width and height attributes. This will also keep the page elements size constant, avoiding the erratic text rearrangement while the page loads.
If your widgets are user driven - be it latest comments or what your cat twitted it's always a good idea to hide long words.
So when someone writes Hellooooooo (and multiply that "o" ten fold), simply use: "overflow: hidden" on your text container. To add a touch of finesse because everyone loves IE, use "overflow: ellipsis" in it's conditional stylesheet.
Escape outputted textFrom a security standpoint it's good to escape everything you output on the page (where possible).
From a w3c compliance standpoint your code may not always validate. For example: http://website.org/?param=x¶m2=y; & should be escaped into & Or you may have something more serious such as an unclosed tag, yet it's very unlikely.
Hopefully this advice will leave your widgets to a boring yet stable experience.