缓存 js 输出

我的 elsewhere 页面通过加载 friendfeed 的 js 文件展现了我在互联网上的足迹,包括我在 twitter 上的信息、在 del.icio.us 上收藏的书签等。但这个 js 文件的输出内容比较大,以至于每次浏览 elsewhere 页面都会出现短暂的停顿,所以我将其进行了缓存,每1小时更新一次,以减少浏览的不良体验。

<?php
$num = 40;
$uri = 'http://friendfeed.com/embed/widget/centeur?v=2&amp;num='.$num.'&amp;hide_logo=1&amp;hide_comments_likes=1&amp;hide_subscribe=1&amp;width=515';
if (!$output = wp_cache_get('friendfeed', 'js_cache')){
if (!class_exists('Snoopy')) include_once(ABSPATH . WPINC . '/class-snoopy.php');
$snoopy = new Snoopy;
$snoopy->fetch($uri);
$output = $snoopy->results;
wp_cache_add('friendfeed', $output, 'js_cache', 3600);
}
?>

<script type="text/javascript"><?php echo $output; ?></script>

Submit Article :- Digg + Del.icio.us + Google Bookmarks + Reddit + Technorati

Tags: ,

This entry was posted on Saturday, November 8th, 2008 at 8:33 pm and is filed under wordpress. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “缓存 js 输出”

gravatar image

西岸 November 10th, 2008 at 7:04 pm | reply

高手就是高手啊。

gravatar image

Centeur November 11th, 2008 at 7:38 am | reply

@西岸:过奖,我最近正在较系统的学习 PHP,呵呵。

Leave a Reply

Please copy the string mJzAWE to the field below: