作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
出于某种原因,对新聊天消息的检查会导致浏览器(以及在某种程度上服务器)负载比我预期的要大。有人看到我可以提高效率、减轻负载的任何方法吗?
// Begin the cycle of refreshing the mini chat after the standard delay.
function startRefreshingMinichat(){
var secs = 30; // Chat checking frequency.
setTimeout(function (){
checkForNewChats();
startRefreshingMinichat(); // Loop the check for refresh.
}, secs*1000);
}
// Check for the latest chat and update if it's different.
function checkForNewChats(){
// Check whether the latest chat doesn't match the latest displayed chat.
// NOTE THAT THIS CALLBACK DOES NOT TRIGGER IMMEDIATELY.
$.getJSON('api.php?type=latest_chat_id&jsoncallback=?', function(data){
var newChats = false;
// Update global data stores if an update is needed.
if(updateDataStore(data.latest_chat_id, 'chat_id', 'latestChatId', 'chat_id')){
newChats = true;
}
if(newChats){ // there are new chats to show.
refreshMinichat(null, 50); // loads new chat content.
}
// Since this callback isn't immediate, any feedback has to occur whenever the callback finishes.
}); // End of getJSON function call.
}
最佳答案
查看CometD 。这是一个 js 长轮询系统,我在与 jQuery 集成的简单聊天系统中取得了一些成功。 (上次我查看时,有一些 jQuery 特定的实现,但我从未找到一个对我来说足够强大的实现。)
关于javascript - 如何使我的 javascript 聊天轮询脚本更加高效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2781245/
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 4 年前。 Improv
我正在寻找清理 Grails Controller 代码的方法。在各种 Controller 中我或多或少有相同的逻辑.. 获取对象 检查是否存在 等等.. 是否有建议的方法可以使 Controlle
我真的很喜欢 PHP,因为: _ 易于开发 Web 应用程序(您可以在 10 分钟内设置 LAMP,然后就可以开始了) _ 简单易学 _ 易于部署(您只需要带有 PHP 模块的 Apache) 我真的
我正在尝试使用 mod_rewrite 将我的博客 URL 转换为更适合 SEO 的格式。我所有的文章都存储在一个简单的 MySQL 数据库中。每个博客文章的网址如下所示: http://www.te
我是一名优秀的程序员,十分优秀!