Search code examples
cssfontsbase64webfonts

How to create a data:application link for a web font?


Since web fonts have some ins-and-outs pertaining to cross-domain hosting, being a developer who provides code for a multitude of clients that want to use such web fonts to leverage their aesthetic quality, can be challenging especially when trying to detail the technical steps of hosting a file and making sure the URL path is pointing to it properly.

Recently, I have come across a webfont that uses a

data:application/font-woff;charset=utf-8;base64, "longHash"

nomenclature and I am not familiar with this.

One great benefit of this is that it seems that this doesn't have the cross-domain pitfalls of using a URL for a font, example here:

http://jsfiddle.net/9336yqkL/1/

If you look at the link you can see that it's a series of alphanumerical characters quite long in length where the URL path typically is.

I wonder, how does one create a path like this?

Help is always appreciated!


Solution

  • Base64 is an encoding scheme for binary. You can use a decoder to get the binary contents of the alphanumerical text that comes after base64,. The entire process is called Data URI Scheme and has a list of pros and cons for using it. http://en.wikipedia.org/wiki/Data_URI_scheme#Advantages_and_disadvantages