Skip to content
New issue

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

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

Already on GitHub? # to your account

Intent to implement: Font loading control in AMP #648

Closed
cramforce opened this issue Oct 16, 2015 · 7 comments
Closed

Intent to implement: Font loading control in AMP #648

cramforce opened this issue Oct 16, 2015 · 7 comments
Assignees
Labels
INTENT TO IMPLEMENT Proposes implementation of a significant new feature. https://bit.ly/amp-contribute-code

Comments

@cramforce
Copy link
Member

Implement an API for controlling timeouts on font loading. Currently most browsers time out after 3 seconds but Safari never times out.

The new amp-font tag allows adding and removing CSS classes from document.documentElement based on whether a font was loaded or is in error-state.

<amp-font 
    font-family="My Font" 
    timeout="3s" 
    on-error-remove-class="my-font-loading" 
    on-error-add-class="my-font-missing"></amp-font>
<amp-font 
    font-family="My Other Font" 
    timeout="3s"
    on-load-add-class="my-other-font-loaded"
    on-load-remove-class="my-other-font-loading"></amp-font>

The tag observes loading of a font and when it loads executes the optional attributes on-load-add-class and on-load-remove-class and when there is any error or timeout runs on-error-remove-class and on-error-add-class.

Using these classes authors can guard whether a font is displayed and get the following results:

  • get a short (e.g. 3s) timeout in Safari similar to other browsers
  • implement FOIT where the page renders with no text before the font comes in
  • increase timeout to over 3s in non-Safari (Do we want to allow that?)
  • make the timeout very short and only use a font if it was already cached.

Implementation:
I believe this is the best article on the topic: https://dev.opera.com/articles/better-font-face/ and this is the best / smallest library: https://github.com/zachleat/fontfaceonload

CC @pbakaus

@cramforce cramforce added the INTENT TO IMPLEMENT Proposes implementation of a significant new feature. https://bit.ly/amp-contribute-code label Oct 16, 2015
@dvoytenko
Copy link
Contributor

This will be a builtin, right?

@cramforce
Copy link
Member Author

No, since it does not actually trigger the font load performance is not critical I think.

@dvoytenko
Copy link
Contributor

But timeout will be since "amp-font" loaded? Or since runtime started?

@dvoytenko
Copy link
Contributor

Also, maybe amp-font-control would be a better name?

@camelburrito
Copy link
Contributor

@cramforce
will the css still contain the @font-face declaration

@font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf");
}

or should i get the url as an attribute in ?

@dvoytenko
Copy link
Contributor

To confirm, we are not directly downloading @font-face here, but rather monitoring when the existing CSS @font-face has been downloaded.

@cramforce
Copy link
Member Author

Yes, what @dvoytenko says: This is not about triggering font loads, just controlling their effect on the page.

font-face is unaffected, but users need to guard usage of the family with the respective classes.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
INTENT TO IMPLEMENT Proposes implementation of a significant new feature. https://bit.ly/amp-contribute-code
Projects
None yet
Development

No branches or pull requests

3 participants