jaredatch / EA-Share-Count

A lean plugin that leverages SharedCount.com API to quickly retrieve, cache, and display various social sharing counts.
85 stars 13 forks source link

javascript method of inserting buttons/count? #41

Closed ramseyp closed 8 years ago

ramseyp commented 8 years ago

Great plugin guys. Have you considered using javascript to display buttons & counts, to deal with aggressive server-side caching?

jaredatch commented 8 years ago

Good question.

So yes, we did sorta discuss this, when the plugin was in its infancy.

The biggest issue raised, and why it was never pursued, was due to potential scaling.

Right now if the site has a front end cache such as Varnish or Nginx, that works in our favor. Since the buttons/counts are are rendered server site, they get cached with the page.

To do more realtime display and side step any caching we'd need to load the share counts over AJAX after page load. This would result in accessing a few post_meta keys on every page load. Knowing how crappy admin_ajax can be and that some sites do tens of thousands of blog post page views a day (if not more - aka Bill's Wester Journalism client) the performance repercussions worried me enough to not go this route.

We were sorta under the assumption, and I realize this isn't always going to be true, that most sites that do have a front-end cache, don't have a super long cache time - at least typically. So while sites that have this configuration don't have share counts that are accurate up to the minute, they usually don't lag behind far enough for it to be an issue.

What I think would be a better solution, would be to develop an addon plugin that runs in conjunction with EASC. What that plugin would do is after page load via JS, update the Share counts directly from the ShareCount API. This way the counts are closer to real time (SC API still has things cached to some degree) but not at the expense of hammering the server with more AJAX calls. I think this would be a good solution, and if I client was ever concerned about the count delay, this would be the solution I recommend. Only downside of this is you will burn through the SC API requests faster, so depending on the site's traffic a paid account might be needed to avoid hitting API call limits.

Let me know if that makes sense of if you have any questions 😀

ramseyp commented 8 years ago

Thanks @jaredatch - I realized after I asked about it, that the API hits would skyrocket if a JS method were used. Since it stores counts locally, and has an update schedule in place, that's the better way to go about grabbing and displaying the counts.

We're testing this on a site right now and so far, it's working out great. Looks like it'll be a good ShareThis replacement.

jaredatch commented 8 years ago

Great. If you have any other feedback or insight just let us know!