moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Font loaded for multiple times

Open isning opened this issue 3 years ago • 2 comments

On Compose js (canvas based) paltform I loaded some fonts to for a customized MaterialTheme, but the fonts seems to be loaded for multiple times, which obviously slow down page loading. image

Is there any workaround to prevent this?

isning avatar Nov 24 '23 07:11 isning

hi. i think you use asFont extension

https://github.com/icerockdev/moko-resources/blob/6b320c12e07e57c866d787841e8a5b41c583808d/resources-compose/src/jsMain/kotlin/dev/icerock/moko/resources/compose/FontResource.js.kt#L18

and as you can see in this extension - result of downloading is saved by produce in compose memory. so if you see multiple load of specific fonts i suggest to check recompositions with changing structure of tree (in this case all remembered for composable data will be cleared)

Alex009 avatar Nov 27 '23 05:11 Alex009

Yes, I used asFont extension, even outside the MaterialTheme scope, it still load for multiple times during the page loading, I think it might be compose things for the Theme recompose for multipose times, so I choose another solution not rely on compose: https://github.com/ISNing/XWareManage/commit/7c3d63ce93efa6bc169f2c33c5c8be3511f59bb4

I think mabe I should close this issue?

isning avatar Dec 18 '23 00:12 isning