11

I am looking at this page.

I can see this in the header. Can someone explain what it does. I can't see any mention of it and what it is used for:

  <script class="js-allow-in-head" src="//use.typekit.net/txx2jfv.js"></script>
  <script class="js-allow-in-head">try{Typekit.load();}catch(e){}</script>

thanks

1
  • It loads Typekit font library and tries to initialize it or to do other things (depends on what is the purpose of the method .load()). try{}catch{} construction catches exceptions (errors) during execution of the code inside of a try{} block, so that there will be no messages in error console and other javascript code on the page will not break. URL written in the way of //site.com/file.js allows browser to select what to use for the load of file.js - the regular http or https protocol and it depends on the protocol used to open html page with that code.
    – Cheery
    Nov 19, 2014 at 7:02

2 Answers 2

19

Typekit is a provider of webfonts. They probably are the only service that benefits from having the script in the head, because it blocks rendering while the fonts download, thus preventing a FOUT (flash of unstyled text)

The script works by fetching some css files that contain the fonts in base64 encoding.

1

//use.typekit.net/txx2jfv.js is the script including in the header of page..this file contain some jquery code...The use of that code is to use beautiful FONTS on your page...check the site https://typekit.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.