views:

20

answers:

1

Is there a way to cache widgets. For example if you place your widgets on high volume websites then each time when someone access that site, a call will be made to your server to get the widget code. This way my server can get too much overloaded just to display the widget . Can I cache the widget HTML code and place it on some server like Akamai. Any suggestions or tips highly appreciated.

Thanks in advance.

A: 

You sure could, but you'd need to be able to get at the widgets somehow. I've found much higher performance (faster response, faster downloads) from EdgeCast vs. Akamai, also.

Say, for instance, you've got the code for a form at http://cdn.mysite.com/form1.html and a user clicks on a link that would bring up that form.

Use something like this as a script:

$(document).ready( function() {
    $(".widget .trigger").click( function() {
        url = $(this).attr("rel");
        $(this).parents(".widget").load(url, function () {
            // Do what needs to be done to the widget code here
           // Example: make it an AJAX form.
        });
    });
});

And then have this Markup:

<div class="widget">
    <a href="javascript:void(0);" rel="http://cdn.mysite.com/form1.html"&gt;Widget Trigger</a>
</div>

And have this on your CDN:

<form action="/ajax/hander/" method="POST">
    <fieldset>
        <legend>This is a pretty cool form</legend>
        <label for="form1input1">Make this cool:</label>
        <input id="form3input1" name="something" type="text" />
        <input type="submit" value="Coolify" />
    </fieldset>
</form>

You could then have some code server side that uploads snippets to your CDN, saves their URL in a database, and generates the links with the appropriate rel tag by pulling that value from something fast like Memcached. That part will vary greatly based on your language of choice.

Zack