diff --git a/embed-github-gist.php b/embed-github-gist.php index 8a574fa..6b9509e 100644 --- a/embed-github-gist.php +++ b/embed-github-gist.php @@ -31,6 +31,10 @@ define('EMBED_GISTHUB_BYPASS_CACHE', false); } +if ( !defined('EMBED_GISTHUB_DEFERRED') ) { + define('EMBED_GISTHUB_DEFERRED', false); +} + /** * Build a cache key * @param int $id GitHub Gist ID @@ -57,6 +61,13 @@ function embed_github_gist_prefer_inline_html() { return EMBED_GISTHUB_INLINE_HTML; } +/** + * Prefer deferred loading and not blocking rendering with document.write? + */ +function embed_github_gist_prefer_deferred_loading() { + return EMBED_GISTHUB_DEFERRED; +} + /** * Gets content from GitHub Gist * @@ -118,12 +129,29 @@ function embed_github_gist($id, $ttl = null, $bump = null, $file = null) { } } else { $urlExtra = $file ? '?file='.$file : ''; - if (defined(EMBED_GISTHUB_USERNAME)) { - $gist .= ''; + if ( embed_github_gist_prefer_deferred_loading() ) { + $randomId = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); + // Load the Gist via JSONP which returns the Gist itself as html and a corresponding CSS resource. + $gist .= ''; + $gist .= '