Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.8k stars 875 forks source link

[BUG] Package adds unnecessary unused fonts to resources in web #773

Closed antdementyev closed 2 years ago

antdementyev commented 3 years ago

Describe the bug:

Using of the package adds unnecessary KaTeX fonts from flutter_math_fork to built resources in web. It increases the size and delays the loading of the Webapp.

HTML to reproduce the issue:

Reference flutter_html in dependencies:

dependencies:
  flutter_html: ^2.1.0

Use it somewhere in code, e.g. in simple Hello-World created by Android-Studio

@override
Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("any")),
      body: Html(data: "something",),        <----  simple using of package
    );
}

Build web project

flutter build web

Built web contains a lot of KaTeX fonts with 660 kB even if they are nowhere used or referenced:

$ ls build/web/assets/packages/flutter_math_fork/lib/katex_fonts/fonts/ 
KaTeX_AMS-Regular.ttf           KaTeX_Fraktur-Bold.ttf          KaTeX_Main-BoldItalic.ttf       KaTeX_Math-BoldItalic.ttf       KaTeX_SansSerif-Italic.ttf      KaTeX_Size1-Regular.ttf         KaTeX_Size4-Regular.ttf
KaTeX_Caligraphic-Bold.ttf      KaTeX_Fraktur-Regular.ttf       KaTeX_Main-Italic.ttf           KaTeX_Math-Italic.ttf           KaTeX_SansSerif-Regular.ttf     KaTeX_Size2-Regular.ttf         KaTeX_Typewriter-Regular.ttf
KaTeX_Caligraphic-Regular.ttf   KaTeX_Main-Bold.ttf             KaTeX_Main-Regular.ttf          KaTeX_SansSerif-Bold.ttf        KaTeX_Script-Regular.ttf        KaTeX_Size3-Regular.ttf
$ du -sh build/web/assets/packages/flutter_math_fork/lib/katex_fonts/fonts/
660K    build/web/assets/packages/flutter_math_fork/lib/katex_fonts/fonts/

and they all are added to built build/web/assets/FontManifest.json

Html widget configuration: See example above

Expected behavior:

No unused fonts and other resources should be added to built resources

Device details and Flutter/Dart/flutter_html versions:

Flutter 2.2.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d79295af24 (6 weeks ago) • 2021-06-11 08:56:01 -0700
Engine • revision 91c9fc8fe0
Tools • Dart 2.13.3
tneotia commented 3 years ago

This is just because we have the plugin bundled in. See #661 which would allow users to opt-in to all packages used, thereby removing unnecessary bloat for users who don't want features like these and instead want basic HTML rendering.

antdementyev commented 3 years ago

Open since May... Until it is done, is there only one way for the issue: just accept it?

tneotia commented 3 years ago

Currently yes, unless you wish to clone it and remove the dependency by hand, and finally point your pubspec to the path of the cloned package.

Because it is such a massive change it has been open for that long, and plus the maintainers of the package (@erickok and/or @ryan-berger) have been pretty busy recently, they have not had time to review those big PRs. Apologies for the inconvenience but we don't really have control over what things our dependencies load, and plus there is not much alternatives to show LaTeX content in Flutter at the moment.

antdementyev commented 3 years ago

ok, thanks for a quick reply

erickok commented 3 years ago

I'm sorry I haven't been able to work much on the package. It will get much better mid August.

A workaround is to override and remove this dependency.

devrobbey commented 3 years ago

Did you have a chance to take a look on this issue @erickok ? Reducing payload could really help making web loading time faster!!

erickok commented 3 years ago

It's connected to the modularisation of the library, which is big but the most important thing we are (slowly) working on.

tneotia commented 2 years ago

Modularization is now complete with v3.0.0-alpha.2!