如何在Twitter嵌入时间线刷新之前设置超时?

如何在Twitter嵌入时间轴上刷新之前设置超时?

我需要更改超时时间来更新我网站上的推特时间线。 目前,每秒Twitter API都会执行ajax请求来更新时间轴。 但是在JS的引擎较慢的浏览器上(换句话说:IE),导致浏览器变慢或者有时会导致浏览器停止工作。

为了解决这个问题,我想在Twitter时间线刷新之前设置超时

我没有在API上找到关于我如何做到这一点的任何参考。

我正在使用以下JS代码导入时间轴:

!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p='https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p "://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); 

为了显示时间表,我使用的HTML代码如下所示:

 

WHAT'S HAPPENING ON TWITTER

有人知道如何解决这个问题?

谢谢。

我相信设置Tweet limit可能是一种选择。

推文限制: To fix the size of a timeline to a preset number of Tweets, use the data-tweet-limit =“5”属性 with any value between 1 and 20 Tweets. The timeline will render the specified number of Tweets from the timeline, expanding the height of the widget to display all Tweets without scrolling. with any value between 1 and 20 Tweets. The timeline will render the specified number of Tweets from the timeline, expanding the height of the widget to display all Tweets without scrolling. 由于窗口小部件具有固定大小,因此在使用此选项时不会轮询更新。

https://dev.twitter.com/docs/embedded-timelines

例如

然后,如果需要,您可以手动更新您的小部件,方法是删除它们重新插入html然后调用。

twttr.widgets.load()

在Twitter上提供的widget.js文件上进行逆向工程。 我找到了一个名为’schedulePolling’的方法,代码如下:

 schedulePolling: function(e) { var t = this; if (this.pollInterval === null) return; e = twttr.widgets.poll || e || this.pollInterval || 1e4, e > -1 && window.setTimeout(function() { this.isUpdating || t.update(), t.schedulePolling() }, e) 

为了增加超时,我在此代码上添加了一个固定值。

 schedulePolling: function(e) { var t = this; if (this.pollInterval === null) return; e = 60000 || e || this.pollInterval || 1e4, e > -1 && window.setTimeout(function() { this.isUpdating || t.update(), t.schedulePolling() }, e)} 

我已经将代码twttr.widgets.poll替换为我想要’60000’的时间;

执行此操作后,使用我的自定义代码保存widget.js。

因此,在此自定义之后,我修改了导入Twitter API的行,将默认值//platform.twitter.com/widgets.js更改为我的自定义文件my-site/js/customized_widgets.js的路径。

结果就是这样。