Using Github Embedded Gists With Turbolinks
09 Apr 14
In this tutorial, I will show you how to make github embedded gists compatible with turbolinks.
As you may have noted following links on this site is a little bit faster if not faster than its normally is. I have achieved this with the help of
Turbolinks gem. This means that I am able to get the bulk of the speed benefits but this comes at a cost as not everything will work as normal.
I ran into some problem trying to use Github embedded gists on this site. They din't work on pages loaded with turbolinks. I have to manually refresh a page to render the Github gists. This got me going crazy, searching every site on the internet looking for a solution. I finally got a solution from an
issue raised on github about the same.
Though its not officially documented, I decided to write it here to act as a reminder for posterity. For those using coffee script simply include this snippet in your js.coffee file
The last thing you now need to to is change all of your gist script tags into divs with a gist class and data attributes for the URL and the file name. Also, use the .json extension instead of .js. Like this:
And your good to go!! This site uses this solution to overcome this problem. Hope this helps someone. Have any comments? Feel free to leave one below.