Parsoid knows which CSS modules are relevant to the page.
Compare view-source:http://parsoid-lb.eqiad.wikimedia.org/enwiki/Earth?oldid=653376982 (uses Math so has ext.math.styles) to view-source:http://parsoid-lb.eqiad.wikimedia.org/enwiki/Forest?oldid=653225044 (no ext.math.styles).
We need to keep track of this information as well. It already affects Math (although apparently not too significantly, since I don't recall any recent bugs about this).
See https://www.mediawiki.org/wiki/Topic:Se6bj880ul40xhjz) (we're missing a style for .mwe-math-fallback-image-inline).