Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Async, embeddable HN share button (github.com/igrigorik)
63 points by igrigorik on April 15, 2012 | hide | past | favorite | 22 comments


There's nothing more sad and somewhat pathetic than a "share on... " button with a single digit counter. Perhaps hide the counter if it's under configurable threshold?


That's a good idea. Ideally a combination of time and points actually: if it's a new article then show the counter, but if its older and low points, then hide the button.


Working on auto-instrumenting the button with Google Analytics trackSocial stuff - stay tuned.


GA instrumentation should be in place now. Go into GA > Traffic Sources > Social Plugins, and you should see it there. (don't forget to change the date range)



For something unrelated, what's the point of code like this?

    <script>
        (function() {
           var hn = document.createElement('script'); hn.type = 'text/javascript';
           hn.async = true; hn.src = 'http://hnbutton.appspot.com/static/hn.js';
           var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(hn, s);
        })();
    </script>
Why not just put in the generated script tag? Moreover, why does it matter where the tag is placed if it's loaded with async as opposed to defer?


For the HN audience you probably could, since we're all on modern browsers. The pattern above is what GA uses to guarantee most consistent behavior across all browsers. It comes down to browser support for the async keyword: http://stackoverflow.com/questions/1834077/which-browsers-su...

As far as async vs. defer, here's a good summary: http://www.sitepoint.com/non-blocking-async-defer/


Great! It would be awesome if it can be made to work with Wordpress (the vanilla hosted site). Or maybe I should just start blogging like a hacker[1, 2]...

[1] http://tom.preston-werner.com/2008/11/17/blogging-like-a-hac...

[2] http://www.allthingsdistributed.com/2011/08/Jekyll-amazon-s3...


Great work, but are you serving `hn.js` from a CDN like CloudFront, so in the event that your website goes down, it doesn't effect others. Also, the url the iframe calls: http://hnbutton.appspot.com/button?title=some-title&url=..., how can we be sure that is always going to be available?


*.appspot.com is Google App Engine. It has built-in redundancy.


I have just installed it to my blog (example: http://ahmetalpbalkan.com/blog/getting-things-done-for-devel...) however submit button never disappears. I would expect it to show 1 points. Can you show me a page that vote count actually works?


The data is coming from thrifdb API (like all other buttons), so there is a small delay in the "true count" and what gets displayed in the button. From what I can tell, its ~within minute(s) accuracy.


Can you expand on thrifdb API? Can't find any relevant search results.


I believe he means http://www.hnsearch.com, I used it to fetch story data too in the past, and I believe hnlike used to work like that too.


Great to hear, thanks!


For me, it shows '4' on your site.


It's a nice button, but, nothing like have 2 HN, FB, Twitter, G+ buttons.

I don't think the "social sharing" idea behind all those buttons is smart at all. It allows for an eventual single winner only, and crap in between (and crap after the winner is "elected" since it wont be cool anymore, everyone will have to have a new button side by side)


> http://hnbutton.appspot.com/static/hn.js

Why is this .js not on Github?


As in, served through Github's CDN (akamai)? Google's App Engine has a few GFE's around the world as well.. :)


Appspot supports SSL while GitHub Pages do not.


Wondering the same thing...


This has been done a few times before but still, well done. Works very well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: