Skip to content

Performace is bad by design #25

@MatmaRex

Description

@MatmaRex

Pasting this from my conversation with Nike earlier today about #22.

MatmaRex: https://github.com/Nikerabbit/jquery.webfonts/blob/11303b7b63bf7dbf89dbfcf4d94a872af68ad0b7/src/jquery.webfonts.js#L177
MatmaRex: also, $elements can contains a few thousand nodes on large pages. getting computed styles for them all is an expensive operation
MatmaRex: this shouldn't be done on page load, and preferably at all
MatmaRex: also, here's a reduced test case for theslowness of this
MatmaRex: visit [[Barack Obama]] on en.wp and run:
MatmaRex: $('*[lang], [style], [class]').each(function(i, element) { $(element).css('fontFamily'); }).length;
MatmaRex: it takes around a second for me on a mid-end laptop
MatmaRex: and that's justfor getting thefont-family, without all the other stuff
MatmaRex: and it's just not possible to make this any faster, other than scanning fewer elements
MatmaRex: maybe you could use the :lang() selector, and just look for elements in given language for each one you have a wbefont defined for
MatmaRex: and load the webfont if you find any
MatmaRex: this uses the "computed" language as well, doesn't require it to be explicitly set with the 'lang' attribute
MatmaRex: but right now that code is broken by design, sorry :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions