Reducing Calls To The Language API
Although fairly quick, the old technique often resulted in strings that were much lower than the API limit. This left a lot of room for improvement, which has been addressed by the latest release.
Basically, all the text nodes are appended to a single element, with each node wrapped in a
<p>. Once this element reaches the character limit, it is passed to Google, which returns a translated version. The script then parses this translation back into the individual text nodes and makes the appropriate adjustments on the page.
Reducing HTTP Requests to my CDN
The Translate This Button is hosted on Amazon Web Services, and with its hundreds of thousands of users, hosting costs do become an issue. The script itself is very lightweight, weighing in at just over 5kb after gzipping, however it makes a couple extra requests for UI imagery.
Performance Improvements In The Future
A future version of the TranslateThis Button will take advantage of these longer strings, which will cut requests to the Language API down by another 90%. As an added bonus, it will no longer require Google’s