pubnub和head.js [英] pubnub and head.js

查看:167
本文介绍了pubnub和head.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人设法正确整合 pubnub 和head.js?

Has anyone managed to integrate pubnub and head.js properly?

Pubnub 希望我将他们的脚本放在页面底部,并带有< div> 标记就在它之前。这确保了`标签在最后一次调用javascript时完全加载。

Pubnub expect me to put their script at the bottom of the page with a <div> tag just before it. This ensures that the ` tag is completely loaded by the time the javascript is called last.

事情是,我的应用程序和pubnub的其余部分都通过head.js加载所以它一直发生JS文件在pubnub订阅/发布密钥之前加载并且它的订阅/发布到'demo'而不是我自己的pubnub区域...

The thing is, the rest of my application and pubnub are loaded through head.js so it keeps happening that the JS files are loaded before the pubnub subscribe/publish key and its subscribing/publishing to 'demo' rather than my own area of pubnub...

有没有任何例子或方式让我只是搞砸这个< div> 元素并直接传递凭证?

Is there any example anywhere or way for me to just screw off this <div> element and pass in the credentials directly?

推荐答案

感谢您通过 Head.JS 使用询问PubNub 。我会帮你快点开始。以下是如何使用 Head.JS 向我们发布PubNub的示例。首先调用head.js()函数,就像通常包括PubNub JS Lib一样。然后在head.js回调中调用PUBNUB.init({})函数:

Thank you for asking about PubNub with Head.JS usage. I will help you get started quickly. The following is an example of how to us PubNub with Head.JS. First call the head.js() function as you normally would including the PubNub JS Lib. Then call PUBNUB.init({}) function inside the head.js callback:

head.js("/jquery.js", "http://cdn.pubnub.com/pubnub-3.3.1.min.js", function() {
    // CREATE A PUBNUB  OBJECT
    var pubnub = PUBNUB.init({
        'publish_key'   : 'pub-key',
        'subscribe_key' : 'sub-key',
        'ssl'           : false
    });
    pubnub.ready();
    pubnub.subscribe({
        channel : 'abc',
        callback : function(message) { alert(message) }
    });
});

就是这样!很简单吧?使用此代码,您可以轻松地将PubNub脚本与 Head.JS 一起使用。如果此处有任何遗漏,请告知我们,我将更新代码和说明。

That's it! Pretty simple right? With this code you will be able to use the PubNub Script with Head.JS easily. If there is anything that may be missing from this, please let me know and I will update the code and description.

这篇关于pubnub和head.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆