GitHub provides us an easy way of embedding gists on a web page. When we navigate to a gist on GitHub, there is a drop-down list element with the default option named "Embed". The value of this is an HTML <script>
tag. The src
attribute of this <script>
tag is nothing but simply the GitHub Gists URL of this gist, with .js
appended to it. When we navigate to this URL (the one that ends with .js
), we observe that this is a JavaScript source file with two document.write
statements. The first document.write
statement adds an HTML <link>
element for the CSS of the embedded gist. The second document.write
is the gist itself.
Embedding gists this way is acceptable for one or two gists (although still being a bad approach) but for more gists, it simply results in a polluted HTML and needless HTTP GET requests for each gist embed link (the HTTP GET requests to the relevant JavaScript files). In other words, every visit to your web page will result in multiple (as many as the number of gists you have