Closed (fixed)
Project:
@font-your-face
Version:
7.x-2.x-dev
Component:
Code (general)
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Jun 2011 at 02:53 UTC
Updated:
4 Jan 2014 at 00:53 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Jazz Li commentedAn issue has been created with regards to Typekit.
http://drupal.org/node/1202474
Comment #2
sreynen commentedMarked #1202474: Load Typekit fonts asynchronously (eliminates FOUT) as a duplicate of this. May open that back up if it proves impossible to do a provider-neutral implementation.
Comment #3
btmash commentedAs far as I can tell, the only sane way to do this right now would be via a javascript loader that changes states so you can control what happens with the font - I was thinking of doing the same way back until I saw the webfont loader project and its why my module was based on it (which isn't perfect but has support for a lot of stuff). I think you could do it via flash as well though that has a number of issues. My 2 cents so far though.
Comment #4
sreynen commentedMy vague plan was to try to pull out the FOUT-related stuff from the Webfont Loader JS, but that was just because I thought it only worked with specific providers. Now that I see the "custom" option, I think just using that JS as-is should work. Doing that via your module would require a few changes to your code, and I'll be happy to write patches, though I probably won't get to it soon. The specific changes I have in mind, if they sound okay to you:
1) Make the font loading a little more flexible, so it can pull info from .fontinfo files, or from other modules, e.g. @font-your-face or Google Fonts.
2) Add a setting for administrators to choose between "show nothing until fonts are ready" or "show unstyled text until fonts are ready" options, as described here:
http://24ways.org/2010/using-the-webfont-loader-to-make-browsers-behave-...
Comment #5
btmash commentedWow, I wasn't expecting this at all. I'm definitely in favor of this :) (1) seems quite doable though (2) will require some more looking into (I do see you have a link and that may be all that needs to be followed?) to see what performance is like. I have typically made all the rulings in my css file(s) so this would change things a fair bit.
Comment #6
jpamental commentedAs long as you can tap into the WebFont Loader so it injects the classes (.wf-inactive .wf-loaded, etc) then the theme can handle dealing with it. You can add CSS that doesn't include the web fonts (i.e. only the fallback fonts) and style them differently with size, line-height and letter-spacing. Works great. Hopefully the article I wrote up on it with example bits will be live on the Fonts.com blog soon - I'll post a link when it is.
Jason
Comment #7
sreynen commentedThis should happen in 7.x-2.x now.
Comment #8
bancarddata commentedsubscribe - the FOUT is pretty painful on a site I am developing right now. Module works great - if you can figure out a way to work around the FOUT, it will be perfect!
Comment #9
btmash commentedI wanted to update things on my end regarding the webfont loader module. I have tacked (2) in #4 and put it in the latest releases of the module. I am not entirely sure on how to describe it (other than default behavior and 'hidden' behavior with a long description to go with it). But the loading is working as intended. Will have to tackle (1) at some point so it satisfies ways to integrate with your work.
Comment #10
btmash commentedI've created the issue at #1285750: Make font loading more flexible (since most of it deals with my module) if you had any suggestions on approaches to make it more flexible.
Comment #11
jpamental commentedJust a followup - now that the web font events are starting to be used, I've written up a way to deal with FOUT pretty effectively here: http://bit.ly/pF5qlr (on Fonts.com's blog) Hope it's helpful!
Jason
Comment #12
btmash commented@jpamental What I have is very close to what you have in your post (though I'm not using the
<noscript>tags.Comment #13
sreynen commentedI've added code to pass enabled Google fonts to BTMash's module when it's enabled, in the dev release. I'd appreciate others testing this before I add similar code to other providers.
Comment #14
btmash commentedAwesome, I'll test and check out how you added the code :)
Comment #15
btmash commentedI had a chance to test it out and what I see happening right now is that the font gets loaded twice (once via the
fontyourface_add_css_in_preprocess($vars, $url, 'remote');and again by the webfontloader (which calls on the font from google). Not entirely sure on how much of an issue it is since the response would likely get cached on the user's end. But adding it into an else statement would clear it up (if using webfontloader, load the font via its function, otherwise use fontyourface preprocessing).Comment #16
btmash commentedAs an example (I don't know if you want to head in this route), the way I had handled this was with the attached diff.
Comment #17
sreynen commentedI didn't realize the web font loader actually loaded the font, which seems kind of obvious now that I type that out. I thought it just watched the load status and updated the class names as the status changed. That patch makes sense to me. I'll try to get that changed soon and also add implementations for other providers.
Comment #18
sreynen commentedThe Google implementation is fixed in the 7.x-2.x-dev release. I'm going to do a final release of 2.0 before adding the other providers.
Comment #19
stevenator commentedJumped in here with @BTMash on IRC this evening.
Went through the Typekit provider for google_webfont_loader_api and saw that the integration is unnecessary as the Typekit js mimics the same methods as the loader. I will try another provider in the next few days and see where I get to helping implement some of the first task that @BTMash is talking about in #4
Comment #20
btmash commentedAlright, I have been able to get fontsquirrel and local imported fonts working. I updated my module's codebase to be a little more flexible (so it can accept various kinds of streams) and it is working against those changes. Attaching patch for review.
Comment #21
sreynen commentedHey BTMash,
In retrospect, my plan to talk about this at the DrupalCon party last night was totally impractical. :) This looks good to me. I'll try to get it committed soon, thanks!
Comment #22
sreynen commentedCommitted.
Comment #24
Cyclodex commentedHi all!
I updated to the dev code and for me the FOUT is still there when using Typekit Font.
I am not 100% sure, but it looks like I have to add some CSS to hide the fonts while the html tag has its
wf-loading-class set.
This now works for me. I just used to hide the whole html with it, because I load a lot of text with downloaded fonts.
I am not sure if this is the correct way, but I didn't found any setting or similar on the dev code.
Is this correct and documented somewhere ? Or should we add these info for other people if it is correct?
I fought a long time to bring these FOUT away...
Regards Cyclodex
Comment #25
btmash commentedHmm, that would be the correct way. I had not modified the code for the typekit provider since that was already using a variant of the webfont loader module's js (as mentioned by @stevenator in http://drupal.org/node/1187682#comment-5546392). I could certainly create a patch for this though we should then do it for all the possible providers then regardless of them using their own js. Providers that I see that could still use it (and that I have it working for in my module) would be:
That *should* cover all the provider modules then. Any thoughts, @sreynen?
Comment #26
Cyclodex commentedAh okay.
I am not sure if we/you should let the users add themselves CSS stuff regarding what to hide:
Could be an option. Thanks for the quick reply !
Comment #27
sreynen commentedAccording to an old blog post on Typekit, the Typekit JS adds the wf-loading class, but does not add any CSS to hide the loading text. My testing confirmed this. The font loader adds the CSS to hide the wf-loading fonts, but it only adds that CSS within _google_webfont_loader_api_load_font(), which is only called when a font is passed in. If we start passing in Typekit fonts, we'll get unneeded JS along with the hiding CSS. So I suggest refactoring the Google Webfont Loader code a bit so that google_webfont_loader_api.hidden.css is added independent of _google_webfont_loader_api_load_font(), based on the same setting, maybe within google_webfont_loader_api_init().
BTMash, how does that sound?
Comment #28
Cyclodex commentedAh so that's why I had to implement my own css styles to handle it...
Comment #29
btmash commentedI can try to split apart the css loading portion some more so it does a check (has the hidden css been requested? yes, add it in regardless.). The way I'm thinking right now is it can be its own function in case things change in the future (tentatively called
_google_webfont_loader_api_add_hidden_css()). The css being added is fairly safe (hopefully a class of 'wf-loading' does not get added in by another module/theme that happens to use the webfont loader module). And it has taken me all of 5 minutes to write it in.With that said...do you really want to load an additional module that is just going to add 6 lines of css? :( Though I agree that webfont loader js is heavier in the sense that other checks are going on which would likely make the processing of the js slower than from typekit.
Comment #30
sreynen commentedHmm, I hadn't thought of it like that. One might ask the same thing about @font-your-face in general. :) But I think the value isn't so much in the specific CSS or JS that gets added as it is in not having to think about how exactly FOUT is handled for any given provider. Having Google Webfont Loader handle FOUT for every provider seems better to me than having it only work for some providers with a different method for others, even if that means only adding 6 lines of CSS in some cases.
Comment #31
btmash commentedAlright, alright, you've strong-armed me with your argument :P I've committed the patch so it should now handle that since typekit comes with its own font-loader variant. So I am now left with figuring out how to handle fontdeck and fonts.com. From what I see fontdeck also seems to use the Webfont Loader library so we just need to see if they already handle FOUT (if not, my commit should take care of it and you don't have to change anything). Alternately, since it is wholly using webfont.js, it could be switched over to what I have and there should be little to no impact in performance.
font.com (ascender) will need to switch over into using the WFL module library instead of the js it provides since I don't see it adding any other code into the page that I could directly work with via css (unless it takes care of itself).
Comment #32
btmash commentedI had a chance to look through what font.com does in the js and it seems like they do handle it themselves so it may not need to be managed. Unless we still want to.
Comment #33
btmash commentedI made a bunch of code changes so it should all be working as expected (with dev - I'm planning to make a stable release of WFL on Monday) so it *should* be resolved. Marking as needs review.
Comment #34
Drave Robber commentedI've been tinkering with @font-your-face for several month now (both 7.x and 6.x), and haven't seen a glimpse of FOUT, so this seems fixed. :)
If someone knows the steps to produce some FOUT, feel free to reopen.
(On a side note, I recently stumbled on some script to deal with FOUT - http://www.webink.com/fout-b-gone/ - although at the moment we don't seem to need it, I'm posting a link just in case we still need to work on this later)