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

Support for font-display #211

Open
iammatthias opened this issue May 16, 2019 · 16 comments · May be fixed by #212
Open

Support for font-display #211

iammatthias opened this issue May 16, 2019 · 16 comments · May be fixed by #212

Comments

@iammatthias
Copy link

Google Fonts is adding support for font-display. It would be great to add support to Typography.js.

More info: https://www.zachleat.com/web/google-fonts-display/

@gbreux
Copy link

gbreux commented May 20, 2019

Agreed :)

Although you can already achieve that in an ugly way by setting the &display=swap query param at the last item of the styles array of the googleFonts props.

googleFonts: [
    {
      name: "Noto Sans JP",
      styles: ["300", "400", "500", "700"]
    },
    {
      name: "Roboto Condensed",
      styles: ["700&display=swap"]
    }
  ]

will be rendered as: http://fonts.googleapis.com/css?family=Noto+Sans+JP:300,400,500,700|Roboto+Condensed:700&display=swap

@iammatthias
Copy link
Author

iammatthias commented May 20, 2019

@gbreux now a bad fix. Ugly, like you said, but it gets the job done. Thanks!

Leaving this open for now, there might be a more elegant way of handling this.

@dakebl dakebl linked a pull request May 21, 2019 that will close this issue
@dakebl
Copy link

dakebl commented May 21, 2019

Hello, I've added fontDisplay as a valid option for the config object in this PR: #212

For example:

{
  fontDisplay: 'swap',
  googleFonts: [
    {
      name: "Noto Sans JP",
      styles: ["300", "400", "500", "700"]
    },
    {
      name: "Roboto Condensed",
      styles: ["700"]
    }
  ]
}

Which would generate a url of: http://fonts.googleapis.com/css?family=Noto+Sans+JP:300,400,500,700|Roboto+Condensed:700&display=swap

@foxdoubt
Copy link

foxdoubt commented Oct 2, 2019

Hi! I noticed #212 is still open from May 20. Any word on how much longer it might be until it's merged?

@iammatthias
Copy link
Author

@foxdoubt the solution shared above by @dakebl works nicely.

@dakebl
Copy link

dakebl commented Nov 21, 2019

Hi! I noticed #212 is still open from May 20. Any word on how much longer it might be until it's merged?

Any thoughts on my PR @KyleAMathews?

@remy
Copy link

remy commented Dec 6, 2019

Hi there, just chiming in on this issue and the related PR - we're running perf tests on our site using typography.js and use font-display: swap is going to greatly improve our 'first meaningful content' and thus speed index.

Hoping it can be merged - unless there's a blocker?

@cbdp
Copy link

cbdp commented Feb 7, 2020

I apologise if this isn't relevant, but the solution proposed by @gbreux also worked for me while using the gatsby-plugin-web-font-loader. I'm leaving it here, if another future googler should stumble by this thread.

Example:

  {
            resolve: `gatsby-plugin-web-font-loader`,
            options: {
                google: {
                    families: [
                        `Vollkorn`, 
                        `Roboto&display=swap`
                    ]
                }
            }
        },

@ndom91
Copy link

ndom91 commented Mar 31, 2020

Unfortunately the workaround mentioned by @gbreux now results in the following:

...Playfair+Display:100,300,500,600&display=swap

I noticed the PR to add an actual option for fontDisplay still wasn't merged. @KyleAMathews any chance you could merge that - #212 from May last year

lehtoinen referenced this issue in lehtoinen/helsinginkullervo-fi Jul 10, 2020
lehtoinen referenced this issue in lehtoinen/helsinginkullervo-fi Jul 10, 2020
* Remove italics
- decrease the need for fonts to be loaded, italics not needed here really and this does improve readability in the end as well

* Add font-display: swap for fontfaces
- uses the trick from https://github.com/KyleAMathews/typography.js/issues/211\#issuecomment-494001270 (while the actual feature PR is still not merged)
@rodrigograca31
Copy link

@ndom91 you just made me waste at least 1 hour 😠

because even though that gets converted it seems it still works fine.

Also. seems this project is dead... ☠️😢

@ndom91
Copy link

ndom91 commented Jul 12, 2020

Well it obviously didn't work for me so we were apparently doing something different. No need to get all angry about it, no one's forcing you to "waste" your time on opensource.

@rodrigograca31
Copy link

rodrigograca31 commented Jul 13, 2020

no worries, I wasn't angry at you. I was just angry at me I guess (was late at night 😂)

You say didn't work for you? Do you still see the "warning" saying text should be visible while fonts load?
(mine went away)

@ndom91
Copy link

ndom91 commented Jul 13, 2020

Okay good to hear haha.

So I ended up not using typography.js actually, so unfortunately I can't comment any further on this specific issue.

@rodrigograca31
Copy link

👍

I also want to remove it from my project. Seem like unnecessary extra code that is not being maintained.
It adds a bunch of JS code to my gatsby blog for "no reason".

@ndom91
Copy link

ndom91 commented Jul 13, 2020

Yeah, if you don't need anythign fancy, just font loading. I suggest you check out Kyle's other typeface-xyz packages. They're simply npm packages which add a css file to import the said font file into your project. That way you can install a font from npm without thinking much about it. Not to mention the performance benefits of hosting fonts on your own domain.

gvdp added a commit to knoorsesv/noorse-site that referenced this issue Sep 25, 2020
gvdp added a commit to knoorsesv/noorse-site that referenced this issue Sep 26, 2020
@andria-dev
Copy link

Does anyone know of any good alternatives to Typography.js that:

  • Is being maintained still.
  • Styles all text-related elements.
  • Provides rhythm() functions or similar.

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.

9 participants