Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User agents and font formats #7

Open
timwhitlock opened this issue May 31, 2018 · 11 comments
Open

User agents and font formats #7

timwhitlock opened this issue May 31, 2018 · 11 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@timwhitlock
Copy link

I have no idea if this is against the API terms of use, but if you were considering expanding your script to download other formats, you might try sending alternative user agent strings to the CSS end point.

I've tested a bunch of browsers and note the following font types are generated:

.woff2
Modern browser user agents produce this (as you are doing already).

.woff
Edge version < 14, e.g:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240

.eot (embedded-opentype)
Ancient Internet Explorer, e.g:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)

.ttf (truetype)
Seems to be the default.

Then presuming you had all these formats, you could generate a rule like this:

@font-face {
  font-family: "Name";
  src:url("font.eot");
  src:url("font.eot#iefix") format('embedded-opentype'),
      url("font.woff2") format("woff2"),
      url("font.woff") format("woff"),
      url("font.ttf") format("truetype");
}
@IonicaBizau
Copy link
Member

Ah, interesting...

I hope it's not against their terms—it's really just simulating the browser downloading the css stuff and fonts.

Currently the Google Chrome user agent is used, but I'm open for accepting contributions. I'm not quite sure how we will merge the results for different agents.

@timwhitlock
Copy link
Author

Yeh, it's only doing what a browser does, but this is Google we're talking about.

I would have sent a pull request, but my Node skills are some years out of date and didn't have the time.

Also, IE is dead, and woff2 is almost universal :)

@IonicaBizau
Copy link
Member

Will leave this issue opened and see what other people think... Honestly I'm not really familiar how different browsers support the fonts. Is there a page where we could see that (how one would have to load for different browsers)?

Also, by using the current user agent (which is currently hardcoded), what browsers should fail to display the fonts?

@timwhitlock
Copy link
Author

Compatibility table here: https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face#Browser_compatibility

In all honesty I use the fallbacks as a matter of standard practice and rarely check the state of this table. I think the only real issue with woff2 compatibility is IE if you need to support it. People with Chrome and FF most likely have recent versions.

@IonicaBizau
Copy link
Member

Oh, I see! Maybe using a different user agent to request woff instead of woff2 would be better then. I'm just wondering what would be the disadvantages when using woff instead of woff2...?

@timwhitlock
Copy link
Author

In my (very isolated) use case, the woff2 file is much smaller.

I'd hold off and see if anyone else requests it. I was just letting you know, because I had gone and pulled down my font in all the formats just for completeness.

@IonicaBizau
Copy link
Member

Well, in my case, I need IE11 support anyways... (for a specific company)

Anyways, will see next week. 😁

@IonicaBizau IonicaBizau added the enhancement New feature or request label Jun 1, 2018
@rosswintle
Copy link

Hi! I just came across this very thing. I used your font downloader but it only got the woff2's and soon people on IE11 were complaining.

You can simulate the difference in Chrome by setting a user agent in the dev tools "console drawer". See this video:

https://cl.ly/3D2a2L2r0227

There's good info about cross-browser font-face usage here: https://css-tricks.com/snippets/css/using-font-face/

Shouldn't be too much work to piece it together from here.

At the very least you should declare the browser support for what you download.

Thanks for the cool script though! Really nice.

@rosswintle
Copy link

Ah. Just noticed that the differences are too great to do a simple addition of a file to a line. I'm getting unicode ranges with my WOFF2's and not with my WOFF's. Maybe not so easy!

@DanielRuf
Copy link

DanielRuf commented Jul 22, 2018

@DanielRuf
Copy link

Also see https://caniuse.com/#search=woff

@IonicaBizau IonicaBizau added the help wanted Extra attention is needed label Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants