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

Font-display support? #22

Closed
valeriosillari opened this issue May 30, 2019 · 6 comments
Closed

Font-display support? #22

valeriosillari opened this issue May 30, 2019 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@valeriosillari
Copy link
Contributor

Lately Google Fonts seems to support (finally) font-display option for better performance.

https://scotch.io/bar-talk/google-fonts-now-supports-font-display

Is it possible to use set it right now with this package?
If not, it could add as feature in a next release?

Got no info about it and asking. It would be awesome :)

@moso
Copy link

moso commented Jun 18, 2019

As per Addy Osmani's tweet it already supports &display=swap.

You can add this to this loader too, however, it only works with single fonts.

Example:

{
    webfontloader: {
        google: {
            families: ['Open+Sans:300:400:600&display=swap']
        }
    },
}

However, if you pipe the fonts (['Open+Sans:300:400|Roboto:300:700']), it doesn't currently work because of Typekit being slow on upgrades. Adding &display=swap to any or both of the fonts in the array doesn't work either - at least not in my tests.

But since this webfontloader is built on top of Typekit's webfontloader, you can make a custom loader and supply the URL's yourself, like so:

{
    webfontloader: {
        custom: {
            families: [
                'Open Sans:n3,n4',
                'Roboto:n3,n7'
            ],
            urls: [
                'https://fonts.googleapis.com/css?family=Open+Sans:300,400&display=swap'
                'https://fonts.googleapis.com/css?family=Roboto:300,700&display=swap'
            ]
        }
    },
}

You can then add two or more fonts if you want. Notice the nx where x is an int, corresponding to the font-weight, and the URLs have to be in the correct order, otherwise you'll get the naming incorrect.

I don't know if @manniL or @mangerlahn wants to wait for the PR on Typekit (it's a month old as of June 2019), or if they can make some magic.

So all in all, it works, you just have to add a few more lines of code 😉

@valeriosillari
Copy link
Contributor Author

Works!!!

Thanks 👍

@manniL
Copy link
Member

manniL commented Jun 18, 2019

Thanks to @moso for the detailed answer.

I'd accept a PR for the README ☺️

@manniL manniL added enhancement New feature or request good first issue Good for newcomers labels Jun 18, 2019
@valeriosillari
Copy link
Contributor Author

Yep! If ok also for @moso I could try to do a PR for the README in the weekend

@valeriosillari
Copy link
Contributor Author

PR done and ready to be checked.

@valeriosillari
Copy link
Contributor Author

Pr merged. Info now are in the ReadMe File. Issue closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants