Webfont Interface ??

34 views
Skip to first unread message

Alice Wonder

unread,
May 7, 2018, 2:04:04 AM5/7/18
to PHP Framework Interoperability Group
Hello,

I'm not a really big fan of WordPress for several reasons but I started using it recently in attempt to find and/or create solutions to the third party tracking mess that WordPress blogs typically are.

One of the sources of tracking is webfonts, most themes not only use Google Fonts but hardcode it into the theme.

I created a simple class that is Google Fonts compatible but allows the blogmaster to optionally define their own font server as long as it is Google Fonts API compatible. It's ugly because WordPress does not support autoloaders so either the class has to be included in the theme or installed in mu-plugins to make sure it available when the theme code runs.

But the part in my class where the font server has to be Google Fonts API compatible to work with my class bothers me.

What I think would be nice is a defined interface. A class implementing the interface does whatever it needs to do for the font server being used.

What a class implementing such an interface should do is

* allow definition of the CSS file server (where the link tag will be used),
* an array of domains to add to the DNS prefetch (empty if same as CSS file server, but if the fonts are on different domains, let dns prefetch do its thing)
* a family with optional arguments for weights and variants
* any additional families etc.

I'm not sure how most font servers work with respect to what parameters are necessary.

I think language subset should not be supported, unicode-range in the generated CSS file is better for that. And in fact Google Fonts ignores the subset parameter when generating the CSS file unless you are using a very old browser (or curl/wget).

The class I wrote to fix WordPress themes and allow alternates to Google Fonts to be used works for Google Fonts and my font server, but it won't work with a lot of the font servers out there.

But if frameworks like WordPress and others that allow themes are to be the most compatible with the various font server options that exist, there should in my opinion be an interface and theme developers write to the interface, allowing the webmaster to change what class implements the interface if they want to use a different font server.

Thoughts?
Reply all
Reply to author
Forward
0 new messages