Skip to content

Instantly share code, notes, and snippets.

@ericrasch
Last active July 4, 2017 03:54

Revisions

  1. ericrasch revised this gist Jan 15, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion TypeKit embed code.php
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@

    <?php
    /**
    * TypeKit's advanced [asyncronous] embed code.
    * TypeKit's advanced [asynchronous] embed code.
    * Source: http://help.typekit.com/customer/portal/articles/649336-embed-code
    * Avg. Load Time: 296ms; 218ms; 298ms
    */
  2. ericrasch revised this gist Jan 15, 2014. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions TypeKit embed code.php
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    /**
    * TypeKit's default embed code.
    * Source: http://help.typekit.com/customer/portal/articles/649336-embed-code
    * Avg. Load Time: 191ms; 198ms; 265ms
    */
    ?>
    <script type="text/javascript" src="//use.typekit.net/xxxxxxx.js"></script>
    @@ -10,8 +11,9 @@

    <?php
    /**
    * TypeKit's advanced embed code.
    * TypeKit's advanced [asyncronous] embed code.
    * Source: http://help.typekit.com/customer/portal/articles/649336-embed-code
    * Avg. Load Time: 296ms; 218ms; 298ms
    */
    ?>
    <script type="text/javascript">
    @@ -29,6 +31,7 @@
    /**
    * Delayed loading of typekit scripts vs Flicker-free loading
    * Source: https://www.farbeyondcode.com/Delayed-loading-of-typekit-scripts-vs-Flicker-free-loading-5-2304.html
    * Avg. Load Time: 66ms; 91ms; 113ms
    */
    ?>
    <script type="text/javascript">
    @@ -64,7 +67,7 @@
    // Does the browser support @font-face?
    test: Modernizr.fontface, // Should return a boolean
    // Yep! Get the fonts
    yep : 'http://use.typekit.com/rndmstr1ng.js',
    yep : 'http://use.typekit.com/xxxxxxx.js',
    complete: function() {
    // Load complete! Tell Typekit to start up
    try { Typekit.load(); } catch(e) {};
  3. ericrasch created this gist Jan 15, 2014.
    74 changes: 74 additions & 0 deletions TypeKit embed code.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    <?php
    /**
    * TypeKit's default embed code.
    * Source: http://help.typekit.com/customer/portal/articles/649336-embed-code
    */
    ?>
    <script type="text/javascript" src="//use.typekit.net/xxxxxxx.js"></script>
    <script type="text/javascript">try{Typekit.load();}catch(e){}</script>


    <?php
    /**
    * TypeKit's advanced embed code.
    * Source: http://help.typekit.com/customer/portal/articles/649336-embed-code
    */
    ?>
    <script type="text/javascript">
    (function() {
    var config = {
    kitId: 'xxxxxxx',
    scriptTimeout: 3000
    };
    var h=document.getElementsByTagName("html")[0];h.className+=" wf-loading";var t=setTimeout(function(){h.className=h.className.replace(/(\s|^)wf-loading(\s|$)/g," ");h.className+=" wf-inactive"},config.scriptTimeout);var tk=document.createElement("script"),d=false;tk.src='//use.typekit.net/'+config.kitId+'.js';tk.type="text/javascript";tk.async="true";tk.onload=tk.onreadystatechange=function(){var a=this.readyState;if(d||a&&a!="complete"&&a!="loaded")return;d=true;clearTimeout(t);try{Typekit.load(config)}catch(b){}};var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(tk,s)
    })();
    </script>


    <?php
    /**
    * Delayed loading of typekit scripts vs Flicker-free loading
    * Source: https://www.farbeyondcode.com/Delayed-loading-of-typekit-scripts-vs-Flicker-free-loading-5-2304.html
    */
    ?>
    <script type="text/javascript">
    /* <![CDATA[ */
    TypekitConfig = {
    kitId: 'xxxxxxx'
    };
    (function() {
    var tk = document.createElement('script');
    tk.src = '//use.typekit.com/' + TypekitConfig.kitId + '.js';
    tk.type = 'text/javascript';
    tk.async = 'true';
    tk.onload = tk.onreadystatechange = function() {
    var rs = this.readyState;
    if (rs && rs != 'complete' && rs != 'loaded') return;
    try { Typekit.load(TypekitConfig); } catch (e) {}
    };
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(tk, s);
    })();
    /* ]]> */
    </script>


    <?php
    /**
    * Delayed Loading Typekit asynchronously with yepnope.js
    * Source: http://icelab.com.au/articles/loading-typekit-asynchronously-with-yepnopejs/
    */
    ?>
    <script>
    Modernizr.load([{
    // Does the browser support @font-face?
    test: Modernizr.fontface, // Should return a boolean
    // Yep! Get the fonts
    yep : 'http://use.typekit.com/rndmstr1ng.js',
    complete: function() {
    // Load complete! Tell Typekit to start up
    try { Typekit.load(); } catch(e) {};
    // Profit!
    }
    }]);
    </script>