Hey everyone,
I'm using two fonts from the google font library by adding them via @import in my css-file. After enabling the font submodule I can not recognize that anything has changed. Google Pagespeed Analysis also says that the two fonts are still blocking the rendering.

Is it required to use @font-face instead of @import or do I'm missing a special setting?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

IckZ created an issue. See original summary.

mikeytown2’s picture

The async fontloader works by rewriting the css; if the css is externally imported then advagg can't rewrite it. Give @font-face a try, should do the trick. The admin/config/development/performance/advagg/font page, under "CSS files with external fonts" shows what CSS files and fonts are being async loaded.

mikeytown2’s picture

Status: Active » Fixed

Marking as fixed. re-open if I was mistaken.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

bryancasler’s picture

@mikeytown2, followed your instructions and tried using @font-face to load local font ("Oswald") from one of the theme's CSS files.

Screenshot

themes/seven/style.css - ( [0 "Lucida Grande"] => Verdana )
themes/seven/jquery.ui.theme.css - ( [0 "Lucida Grande"] => Verdana )
themes/seven/reset.css - ( [0 "Helvetica Neue"] => Helvetica )
sites/all/themes/versatile/css/schemes/site-template.css - ( [0 "Helvetica Neue"] => Helvetica [1 "Helvetica Neue"] => Helvetica )

Since "CSS files with external fonts" does not show Oswald listed, I assume that means it is not being Asynchronously loaded. Any suggestions?

bryancasler’s picture

Priority: Normal » Minor

Updating priority.

mikeytown2’s picture

Status: Closed (fixed) » Active

Assuming you've flushed the cache. Where's that CSS file located?

bryancasler’s picture

I had flushed the cache, but checked again just to make sure. No change. Fonts are in their own folder within the theme.

Structure
theme/css/schemes/site-template.css
theme/fonts/Oswald-Regular.woff

Screenshot
http://d.pr/i/unNu

mikeytown2’s picture

Can you upload the CSS files that use the font so I can reproduce this issue?

bryancasler’s picture

@font-face is line 17

http://pastebin.com/raw/y8qRmtpC

bryancasler’s picture

As an experiment, I moved the font-face code into its own CSS file and then put that as first in the list within the theme's .info file. After flushing cache and confirming the new CSS file is loading, I checked what was listed under "CSS files with external fonts" and nothing had changed.

mikeytown2’s picture

Quick glance at this and these font's do not have a fallback; thus async font loading isn't going to work; it doesn't know what to use instead of Oswald.

/**Nice Menu Design**/
#sf-main-menu {
    font-family: "Oswald";
    font-size: 13px;
    font-weight: normal;
    color: #777;
    margin: 0;
    padding: 0;
}

#sf-main-menu li a {
    float: left;
    display: block;
    line-height: 39px;
    color: #888;
    text-decoration: none;
    margin: 0;
    padding: 0 11px;
    font-family: "Oswald";
    text-transform: uppercase;
}

.member-toolbar .site-title .pane-content {
    font-family: "Oswald";
    text-transform: uppercase;
}

.member-toolbar .member-navigation a,.member-toolbar .profile a,.member-toolbar .logout a {
    padding: 0 5px;
    height: 37px;
    margin: 0;
    padding: 3px 10px 0;
    font: 13px/34px Arial,sans-serif;
    font-family: "Oswald";
    text-transform: uppercase;
}

#user-register-form .pos-title {
    font-family: "Oswald";
    text-transform: uppercase;
    font-size: 25.888px;
    margin-bottom: 15px;
    display: inline-block;
}

#privacy-warning .private {
    background: #8fa136 url(/sites/all/themes/versatile/images/button-color-sprite_v2.png) no-repeat -207px 0;
    font-family: "Oswald";
    text-transform: uppercase;
    color: #fff;
    padding: 5px 13px 5px 12px;
    margin-right: 13px;
    display: inline-block;
}

.title-bump {
    height: 45px;
    font-family: "Oswald";
    text-transform: uppercase;
    font-size: 25.888px;
}

These 2 have a fallback so they should be listed. Will see what happened. Most likely it's an issue with parsing font; above is font-family.

.profile_log_out {
    text-align: right;
    background-color: #2d2d2d;
    font: normal 13px/37px "Oswald",arial,verdana,tahoma,sans-serif;
    text-transform: uppercase;
}

.member_toolbar_v2 .pane-content {
    color: #777;
    height: 39px;
    background-color: #2d2d2d;
    margin: 0;
    padding: 0;
    z-index: 99999;
    font: normal 13px/37px "Oswald",arial,verdana,tahoma,sans-serif;
    text-transform: uppercase;
}

bryancasler’s picture

Thanks for the follow up! Eliminated the use of Font to simplify things, and added the fallbacks to font-family. Now they show up under "CSS files with external fonts". Despite that, the fallback is always used and I'm still not seeing a cookie being set by Font Face Observer or any of its files being loaded. I double checked that Font-Face Observer is in the correct location, with the correct naming, and all files are there.

Updated CSS
http://pastebin.com/raw/ZRtY2rVL

Adv Agg Settings
http://d.pr/i/S2xH

mikeytown2’s picture

Title: How to use google @import fonts with async fontloader » Parse the font property for fonts.

The external version of https://github.com/bramstein/fontfaceobserver is 2.x the 7.x-2.18 version and below only works with the 1.x version of fontfaceobserver. This is fixed in the latest dev of advagg.

  • mikeytown2 committed 6684af0 on 7.x-2.x
    Issue #2699589 by mikeytown2: Parse the font property for fonts
    
mikeytown2’s picture

Status: Active » Fixed
FileSize
9.36 KB

I've added in support for parsing font and font-family now. Updating to the latest dev of advagg should fix the issue with using the latest version of fontfaceobserver.

If you open the console you should see a js error with the versions that you're using.

bryancasler’s picture

Doesn't seem to have resolved the issue. And now the Admin Theme has its font defaulting to the last fallback font listed in each of its definitions.

Going to keep playing around to see if I can provide any more concrete feedback.

mikeytown2’s picture

Status: Fixed » Active
bryancasler’s picture

Logs are reporting the following:

Warning: file_get_contents(public://ctools/css/5bee440bb9f6b9b48aea1731a1edb727.css): failed to open stream: "DrupalPublicStreamWrapper::stream_open" call failed in advagg_font_admin_settings_form() (line 108 of /srv/bindings/bbf404295e8b4600915b63a91bda1bea/code/sites/all/modules/advagg/advagg_font/advagg_font.admin.inc).

I'm also still not seeing a font face observer JS being loaded or a cookie being set. If it matters, the site is on Pantheon.

mikeytown2’s picture

Do you see font data in the Drupal.settings.advagg_font variable in the js browser console?

That warning can be ignored; ctools creates and removes css files on a regular basis. This patch makes the errors go away; it doesn't solve the issue you're having.

  • mikeytown2 committed b83224d on 7.x-2.x
    Issue #2699589 by mikeytown2: ignore file_get_contents() errors.
    
mikeytown2’s picture

Status: Needs review » Fixed
mikeytown2’s picture

Status: Fixed » Active

  • mikeytown2 committed d3743e0 on 7.x-2.x
    Issue #2699589 by mikeytown2: Fix some issues with the font parser.
    
mikeytown2’s picture

Status: Active » Fixed
FileSize
3.54 KB

This has been committed and should fix the issues.

bryancasler’s picture

@mikeytown, I'm seeing the font data in the JS console (see screenshot). I'm still seeing the custom font getting completely stripped from the generated CSS files for both the default and admin theme. Looks like it might be stripping any font name in quotes.

JS Console:: http://d.pr/i/14ar0
Cookies being loaded: http://d.pr/i/93CU
Async Font Loader Settings: http://d.pr/i/2Xm9

Input CSS with Custom Font

@font-face {
  font-family: 'Oswald';
  src: url('../../fonts/Oswald-Regular.eot'); /* IE9 Compat Modes */
  src: url('../../fonts/Oswald-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('../../fonts/Oswald-Regular.woff') format('woff'), /* Pretty Modern Browsers */
       url('../../fonts/Oswald-Regular.ttf')  format('truetype'), /* Safari, Android, iOS */
       url('../../fonts/Oswald-Regular.svg#svgOswald') format('svg'); /* Legacy iOS */
}
#sf-main-menu li a {
    float: left;
    display: block;
    line-height: 39px;
    color: #888;
    text-decoration: none;
    margin: 0;
    padding: 0 11px;
    font-family: "Oswald", Arial, sans-serif;
    font-size: 13px;
    text-transform: uppercase;
}

AdvAgg Output

#sf-main-menu li a {
    float: left;
    display: block;
    line-height: 39px;
    color: #888;
    text-decoration: none;
    margin: 0;
    padding: 0 11px;
    font-family: Arial,sans-serif;
    font-size: 13px;
    text-transform: uppercase;
}

This issue is also affecting the Seven admin theme.
Seven Theme Input

body {
    color: #000;
    background: #fff;
    font: normal 81.3%/1.538em "Lucida Grande","Lucida Sans Unicode",sans-serif;
}

AdvAgg Output

body {
    color: #000;
    background: #fff;
    font: normal 81.3%/1.538em sans-serif;
}
mikeytown2’s picture

Status: Fixed » Active

In the outputed css there should be a new rule that has the stripped font in it. Cookie gets set via js. If the cookie isn't there; that's an issue with the external js lib getting loaded, or the local js not working; can also mean the font isn't being downloaded by the browser.

bryancasler’s picture

Confirmed that the CSS is being loaded into another file. Didn't realize that was how it worked, sorry for the confusion.

As for the external/local JS of FontFaceObserver, I'm not sure why it's not loading. No errors are being kicked up by the page. Also no idea why the cookie isn't being set.

Anything I can do to help you troubleshoot further?

mikeytown2’s picture

Try loading the library locally. The admin page has instructions on how to do that.

bryancasler’s picture

The site has had a local copy this whole time. Even tried removing it to use the fallback, no change. Then re-uploaded a fresh download of the library, still no change. http://d.pr/i/lBVJ And the status report page reports that the library is up to date. http://d.pr/i/gGxB

Going to start removing JS libraries from the theme and see if a conflict is somehow happening.

mikeytown2’s picture

Will also say that the latest version is 2.0.5. I'm not sure how you're getting 2.0.4 for the external version as that gets it's info from https://cdn.rawgit.com/bramstein/fontfaceobserver/master/package.json

You might have some rules in your apache/nginx setup stripping etags or the last-modified header.

bryancasler’s picture

The server is showing that the current version is in the libraries folder, but as you can see from the screenshot it's getting 2.0.4 from somewhere.

Looking into this further, I found this Pantheon page that says:

AdvAgg - Advanced CSS/JS Aggregation
Issue: We do not recommend using AdvAgg as it can cause conflicts with Varnish caching leading to various errors, such as Adv CSS/JS Agg – HTTP Request Error HTTP requests to advagg for css files are not getting through or Adv CSS/JS Agg – HTTP Request Error HTTP requests to advagg for js files are not getting through.

If it's Pantheon's configuration that's causing the issue, then I'm afraid there's not much I can do about that.

mikeytown2’s picture

I should get a dev box setup so I can test it out over there.

  • mikeytown2 committed fc654b8 on 7.x-2.x
    Issue #2699589 by mikeytown2: If on pantheon skip far future check and...
mikeytown2’s picture

This will make those issues go away. Will work on the font thing next

  • mikeytown2 committed d619ad6 on 7.x-2.x
    Issue #2699589 by mikeytown2: Give better instructions for installing...
mikeytown2’s picture

This has also been committed. I think the issue for you was that you don't have the libraries module installed. Will come back to this on monday as I don't see any cookies getting set.

bryancasler’s picture

Hey Mikeytown2, won't have time to test the patch until later in the week but the libraries module is definitely installed. And the Status page is even reporting the presence of fontfaceobserver (http://d.pr/i/gGxB).

mikeytown2’s picture

Looking into this and another issue that might be affecting you is if the css file with the font has the preprocess attribute set to false. You can get around this by installing the advagg_mod module and checking the "Enable preprocess on all CSS" button

  • mikeytown2 committed eb18f0d on 7.x-2.x
    Issue #2699589 by mikeytown2: Better font status report.
    
mikeytown2’s picture

Status: Active » Fixed
FileSize
3.15 KB

This is a better status report. Also believe this is fixed; got this working on pantheon by using advagg_mod.

bryancasler’s picture

Trying to update with the latest dev gives me the following error.

Parse error: syntax error, unexpected '[' in /srv/bindings/3d4644228b094e23a34065d19d8c87f8/code/sites/all/modules/advagg/advagg.install on line 2009

The site is running PHP 5.3.29

Also tried disabling Adv Agg modules, unintalling them, and reinstalling with the latest Dev but got the same error.

  • mikeytown2 committed b607976 on 7.x-2.x
    Issue #2699589 by mikeytown2: Fix php error.
    
mikeytown2’s picture

Thanks for the heads up on that! Don't know why it didn't throw an error on Pantheon.
http://cgit.drupalcode.org/advagg/commit/?id=b607976

mikeytown2’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.