Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:17:57+00:00 2026-06-11T02:17:57+00:00

I’m using Font-Awesome, but while the font files are not loaded, the icons appear

  • 0

I’m using Font-Awesome, but while the font files are not loaded, the icons appear with .

So, I want these icons to have display:none while files are not loaded.

@font-face {
  font-family: "FontAwesome";
  src: url('../font/fontawesome-webfont.eot');
  src: url('../font/fontawesome-webfont.eot?#iefix') format('eot'), url('../font/fontawesome-webfont.woff') format('woff'), url('../font/fontawesome-webfont.ttf') format('truetype'), url('../font/fontawesome-webfont.svg#FontAwesome') format('svg');
  font-weight: normal;
  font-style: normal;
}

How do I know that these files have been loaded and I’m finally able to show the icons?

Edit:
I’m not talking when the page is loaded (onload), because the font could be loaded before the whole page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:17:59+00:00Added an answer on June 11, 2026 at 2:17 am

    Now on GitHub: https://github.com/patrickmarabeas/jQuery-FontSpy.js

    Essentially the method works by comparing the width of a string in two different fonts. We are using Comic Sans as the font to test against, because it is the most different of the web safe fonts and hopefully different enough to any custom font you will be using. Additionally we are using a very large font-size so even small differences will be apparent. When the width of the Comic Sans string has been calculated, the font-family is changed to your custom font, with a fallback to Comic Sans. When checked, if the string element width is the same, the fallback font of Comic Sans is still in use. If not, your font should be operational.

    I rewrote the method of font load detection into a jQuery plugin designed to give the developer the ability to style elements based upon whether the font has been loaded or not. A fail safe timer has been added so the user isn’t left without content if the custom font fails to load. That’s just bad usability.

    I have also added greater control over what happens during font loading and on fail with the inclusion of classes addition and removal. You can now do whatever you like to the font. I would only recommend modifying the fonts size, line spacing, etc to get your fall back font as close to the custom as possible so your layout stays intact, and users get an expected experience.

    Here’s a demo: http://patrickmarabeas.github.io/jQuery-FontSpy.js

    Throw the following into a .js file and reference it.

    (function($) {
    
        $.fontSpy = function( element, conf ) {
            var $element = $(element);
            var defaults = {
                font: $element.css("font-family"),
                onLoad: '',
                onFail: '',
                testFont: 'Comic Sans MS',
                testString: 'QW@HhsXJ',
                delay: 50,
                timeOut: 2500
            };
            var config = $.extend( defaults, conf );
            var tester = document.createElement('span');
                tester.style.position = 'absolute';
                tester.style.top = '-9999px';
                tester.style.left = '-9999px';
                tester.style.visibility = 'hidden';
                tester.style.fontFamily = config.testFont;
                tester.style.fontSize = '250px';
                tester.innerHTML = config.testString;
            document.body.appendChild(tester);
            var fallbackFontWidth = tester.offsetWidth;
            tester.style.fontFamily = config.font + ',' + config.testFont;
            function checkFont() {
                var loadedFontWidth = tester.offsetWidth;
                if (fallbackFontWidth === loadedFontWidth){
                    if(config.timeOut < 0) {
                        $element.removeClass(config.onLoad);
                        $element.addClass(config.onFail);
                        console.log('failure');
                    }
                    else {
                        $element.addClass(config.onLoad);
                        setTimeout(checkFont, config.delay);
                        config.timeOut = config.timeOut - config.delay;
                    }
                }
                else {
                    $element.removeClass(config.onLoad);
                }
            }
            checkFont();
        };
    
        $.fn.fontSpy = function(config) {
            return this.each(function() {
                if (undefined == $(this).data('fontSpy')) {
                    var plugin = new $.fontSpy(this, config);
                    $(this).data('fontSpy', plugin);
                }
            });
        };
    
    })(jQuery);
    

    Apply it to your project

    .bannerTextChecked {
            font-family: "Lobster";
            /* don't specify fallback font here, do this in onFail class */
    }
    
    $(document).ready(function() {
    
        $('.bannerTextChecked').fontSpy({
            onLoad: 'hideMe',
            onFail: 'fontFail anotherClass'
        });
    
    });
    

    Remove that FOUC!

    .hideMe {
        visibility: hidden !important;
    }
    
    .fontFail {
        visibility: visible !important;
        /* fall back font */
        /* necessary styling so fallback font doesn't break your layout */
    }
    

    EDIT: FontAwesome compatibility removed as it didn’t work properly and ran into issues with different versions. A hacky fix can be found here: https://github.com/patrickmarabeas/jQuery-FontFaceSpy.js/issues/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I want to construct a data frame in an Rcpp function, but when I
I have a bunch of posts stored in text files formatted in yaml/textile (from
i want to parse a xhtml file and display in UITableView. what is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.