I updated my site to utilize html5 history and ajax recently. One of the challenges I faced was how to handle Gist embeds. Since they only consist of a single script tag it initially seemed like there wasn’t a lot to go on. Not to mention that it would trigger a document.write()
… and that would naturally ruin my site if it were triggered dynamically.
After looking some more at this embed system I found out that the Gist embed also has a json version which gives you its HTML content and a link to a stylesheet that it must load. With this info, I made a small jQuery snippet that would replace all these script elements with the actual HTML from the Gist
Please do note that I used a function called add_stylesheet_once
in the script displayed above. This is purely because I didn’t want the same stylesheet to embedded many, many times after navigating a few pages containing Gists.
Here are some other posts you may like
Electric power companies, in general, are pretty much the same. Tibber however, is unlike any electricity company I had seen before. They try to utilise the data we get from smart devices, which they also sell, to save electricity, money and the environment, as well as improving comfort. It’s a…
Update: The referral program is coming to an end, Febuary 1st. To qualify for 6 months of free supercharging, use a referral code before this date at the purchase of a Tesla Model 3, S or X. https://twitter.com/elonmusk/status/1085771520058679297 Tesla certainly does things differently. One thing that really puts this into…
A few years ago, I invested in the Satechi 108W PRO USB-C PD Desktop Charger, which served its purpose well for quite some time. However, as the device collection in our home expanded and my need for organization grew, I decided to give the Satechi Dock5 a try. The Satechi…