Twitter Buttons

Official Implementation

  <a href="" class="twitter-share-button" data-url="" data-size="large">Tweet</a>
    var js, fjs = d.getElementsByTagName(s)[0];
    if (!d.getElementById(id)){
      js = d.createElement(s); = id;
      js.src = "//";


If all of your tweet buttons explicitly set the url and text properties (either through query parameters or data attributes), you can use either solution. If not, and any or all of your tweet buttons rely on using the current url and document title, you must use the second solution.

The first solution is less work to implement, but the second might be faster since it only runs the widgets.js script once, on the initial page load.

Solution #2 is implemented on this site.

Solution #1

Replace the supplied javascript snippet with an external script tag pointing to

  <a href="" class="twitter-share-button" data-url="" data-size="large">Tweet</a>
  <script src="//"></script>

Solution #2

Remove the script from the body and load the following script inside the <head>.

COFFEESCRIPTtwttr_events_bound = false

$ ->
  loadTwitterSDK ->
    bindTwitterEventHandlers() unless twttr_events_bound

bindTwitterEventHandlers = ->
  $(document).on 'page:load', renderTweetButtons
  twttr_events_bound = true

renderTweetButtons = ->
  $('.twitter-share-button').each ->
    button = $(this)
    button.attr('data-url', document.location.href) unless'url')?
    button.attr('data-text', document.title) unless'text')?

loadTwitterSDK = (callback) ->
  $.getScript("//", callback)

Related Issues: #119

Credit: Nick Reed

All solutions should be considered unofficial. There is no guarantee that a given solution will work with your application. If you find that a solution is insufficient, please let me know by submitting an issue on Github.