Conditionally load fonts on [Bedrock]


5 years ago
5 years ago


(Reporter: cmore, Assigned: craigcook)


Firefox Tracking Flags

(Not tracked)


(Whiteboard: [kb=1235338] )



5 years ago
Currently, the sandstone theme on Bedrock loads 6 .woff fonts:

OpenSans-Regular-webfont.woff?2013 	83.4 kB
OpenSans-Bold-webfont.woff?2013 	62.5 kB
DroidNaskh-Regular.woff 	101.4 kB
DroidNaskh-Bold.woff 	105.9 kB
OpenSans-Semibold-webfont.woff?2013 	63.3 kB
OpenSans-Light-webfont.woff?2013 	61.8 kB

Two of those fonts are the DroidNaskh fonts that total in 207.3kb. Those fonts are loaded on all page requests regardless of what languages the visitor is using.

If we were to conditionally load those fonts for only the locales that need them, we instantly shave off 200k from the page size. The /firefox/new/ page is currently 868k and removing these fonts from non-Arabic locales, will reduce the page size by by 23%.


5 years ago
Whiteboard: [kb=1235338]

Comment 1

5 years ago
We can pull those @font-face rules out of the external CSS and put them into an embedded style in the base template with some conditional logic:

{% if LANG in ['ar','fa'] %}
@font-face { etc }
{% endif %}

This does, however, mean the rare page with mixed content -- a page in another language that contains some Arabic or Persian text -- the Arabic/Persian bits wouldn't render in the Naskh font, it would fall back to the system default.

If there are strong objections to embedding the style in the template we could
Assignee: nobody → craigcook.bugz

Comment 2

5 years ago
doh, clicked too soon. As I was saying...

If there are strong objections to embedding the style in the template we could have a separate external style sheet, but I'm not sure if that's better apart from code purity.

Comment 3

5 years ago
Merged to master in

The code references this bug so this will serve as documentation for future generations who may find this blob of CSS in the base HTML template and wonder why it's there. This is, admittedly, a bit of a hack, and we may find a better method to address the problem in the future. 

There are other languages that may want their own webfonts as well, so if it comes a point where we're adding numerous embedded conditional blocks we should explore other options instead of further polluting the templates.

Also, these embedded style blocks should only contain @font-face declarations. Don't use this method for any other language-specific styling. Keep CSS in external CSS files whenever possible. We have other hooks for styling things for particular languages (attribute selectors or a body class).
Last Resolved: 5 years ago
Resolution: --- → FIXED

Comment 4

5 years ago
Default and no droid fonts:

Droid and default fonts:

Droid and default fonts:

671k now:!/cs7k6F/

That's a 197k savings. Nice!
You need to log in before you can comment on or make changes to this bug.