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

Downloads TTF files instead of WOFF/WOFF2 #1

Closed
aristath opened this issue Jan 10, 2024 · 5 comments · Fixed by #3
Closed

Downloads TTF files instead of WOFF/WOFF2 #1

aristath opened this issue Jan 10, 2024 · 5 comments · Fixed by #3

Comments

@aristath
Copy link
Member

This was brought up in the Gutenberg repo (see WordPress/gutenberg#55049 and WordPress/gutenberg#57706), as well as WP's Slack.
Currently we're downloading .ttf files which are quite large and don't support all features that modern font-families have.
We should instead download .woff files, or - ideally - .woff2.
We should be able to do that by passing a user-agent in the fetch call on

newApiData = await fetch(`${API_URL}${API_KEY}`);

User-agents we can use:
If we want to get woff files, then the one below is the recommended user-agent since it's the only one that also supports unicode-ranges

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8

If we want to get woff2 files, then this one will do:

Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0

cc @matiasbenedetto

@luminuu
Copy link
Member

luminuu commented Jan 10, 2024

An alternative approach would be using the capability parameter with WOFF2 as value, as per the Google Fonts documentation: https://developers.google.com/fonts/docs/developer_api#api_url_specification

@swissspidy
Copy link
Member

Yes this really should use the capability parameter where possible, no user agent wizardry

@aristath
Copy link
Member Author

Even better 👍

@matiasbenedetto
Copy link
Collaborator

An alternative approach would be using the capability parameter with WOFF2 as value, as per the Google Fonts documentation: https://developers.google.com/fonts/docs/developer_api#api_url_specification

This option seems to be new in the Google Fonts API. It didn't exist (or at least I didn't notice it) a few months ago while creating this repo. Good to know that now we have this option available. I think switching from ttf to woff2 should be simple now.

@aristath
Copy link
Member Author

aristath commented Jan 11, 2024

This option seems to be new in the Google Fonts API. It didn't exist (or at least I didn't notice it) a few months ago while creating this repo.

Oh it's definitely new... that's why I initially suggested using the user-agent, we've been using that method for years 'cause until recently there was no other way to do it 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants