What are the best practices for including and using PubNub in a web browser (JavaScript) environment?

Use the following set of rules to ensure cross platform compatibility, highest performance and best user experience to handle the many edge cases prevalent in today's large variety of web platforms:

  1. Never include JavaScript in the <head> tag
  2. Place JavaScript <script> tags at the bottom of the <body> tag
  3. Use the example below to ensure best coverage:
    <div id=pubnub origin=pubsub.pubnub.com pub-key=demo sub-key=demo></div>
    <script src="http://cdn.pubnub.com/pubnub-3.3.min.js"</script>
            // LISTEN
            PUBNUB.subscribe({"channel" : "hello_world", callback : alert})
            // SEND
            PUBNUB.publish({"channel" : "hello_world", message : "Hi there!"})

And be sure to stay up to date as we release newer versions of the JavaScript SDK and always used the version CDN.