Search code examples
cssfontsfont-facewebfonts

how to prevent @font-face to use local files instead of server files?


Visiting a website i have found out the menu links were abnormally bolder than wile watching the same page from my collegue computer with same browser. Deleting the corresponding font from my windows font folder corrected the difference.

My question is how preventing this possibility when designing css fonts on a website


Solution

  • Most @font-face at-rules begin with a local(name-of-local-file) and then a reference to your distant url(/on/server/teh-webfont.woff).

    Browsers will try, in this typical situation, to use the local file and if they find nothing will continue by downloading from your server the distant asset. If they find a local matching font, then they'll use it immediately and will stop their search of a font thus they won't download and use your distant asset.

    Conclusion: don't use local() and only keep those url(). It's the contrary of this SO answer

    Example without local() and many url() corresponding to many formats. Browsers will download the first one that please them, not 2+ of them:

    @font-face {
        font-family: 'Gudea';
        src: url('./fonts/gudea/Gudea-Regular-webfont.eot');
        src: url('./fonts/gudea/Gudea-Regular-webfont.eot?#iefix') format('embedded-opentype'),
             url('./fonts/gudea/Gudea-Regular-webfont.woff2') format('woff2'),
             url('./fonts/gudea/Gudea-Regular-webfont.woff') format('woff'),
             url('./fonts/gudea/Gudea-Regular-webfont.ttf') format('truetype'),
             url('./fonts/gudea/Gudea-Regular-webfont.svg#gudearegular') format('svg');
        font-weight: normal;
        font-style: normal;
    }