简体   繁体   English

pubnub和head.js

[英]pubnub and head.js

Has anyone managed to integrate pubnub and head.js properly? 有没有人设法正确整合pubnub和head.js?

Pubnub expect me to put their script at the bottom of the page with a <div> tag just before it. Pubnub希望我把它们的脚本放在页面底部,前面有一个<div>标签。 This ensures that the ` tag is completely loaded by the time the javascript is called last. 这确保了`标签在最后调用javascript时完全加载。

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... 问题是,我的应用程序和pubnub的其余部分都是通过head.js加载的,因此它继续发生JS文件在pubnub订阅/发布密钥之前加载并且它的订阅/发布到'demo'而不是我自己的pubnub区域...

Is there any example anywhere or way for me to just screw off this <div> element and pass in the credentials directly? 有没有任何例子或方式让我只是搞砸这个<div>元素并直接传递凭证?

Thank you for asking about PubNub with Head.JS usage. 感谢您询问有关Head.JS用法的PubNub I will help you get started quickly. 我会帮你快点开始。 The following is an example of how to us PubNub with Head.JS . 以下是如何使用Head.JS向我们发布PubNub的示例 First call the head.js() function as you normally would including the PubNub JS Lib. 首先调用head.js()函数,就像通常包括PubNub JS Lib一样。 Then call PUBNUB.init({}) function inside the head.js callback: 然后在head.js回调中调用PUBNUB.init({})函数:

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) }
    });
});

That's it! 而已! Pretty simple right? 很简单吧? With this code you will be able to use the PubNub Script with Head.JS easily. 使用此代码,您将能够轻松地使用带有Head.JS的PubNub脚本。 If there is anything that may be missing from this, please let me know and I will update the code and description. 如果有任何遗漏,请告诉我,我将更新代码和说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM