开发者

can widgets be cached?

Is there a way to cache widgets. For example if you place your widgets on high volume websites then eac开发者_开发问答h 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.


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">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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜