I would use a fenced code block in your markdown files, conditionally adding the JavaScript library if the page has one or more echarts.
git clone --single-branch -b hugo-forum-topic-45500 https://github.com/jmooring/hugo-testing hugo-forum-topic-45500
cd hugo-forum-topic-45500
hugo server
hugo server
Start building sites …
hugo v0.111.3+extended linux/amd64 BuildDate=2023-03-16T08:41:31Z VendorInfo=debian:0.111.3-1
ERROR 2023/07/28 13:59:40 render of "page" failed: "/home/micro/testing/hugo-forum-topic-45500/layouts/_default/baseof.html:2:15": execute of template failed: template: tests/single.html:2:15: executing "tests/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2023/07/28 13:59:40 render of "page" failed: "/home/micro/testing/hugo-forum-topic-45500/layouts/_default/baseof.html:2:15": execute of template failed: template: tests/single.html:2:15: executing "tests/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2023/07/28 13:59:40 render of "home" failed: "/home/micro/testing/hugo-forum-topic-45500/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/home.html:2:15: executing "_default/home.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2023/07/28 13:59:40 render of "section" failed: "/home/micro/testing/hugo-forum-topic-45500/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/list.html:2:15: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Error: Error building site: failed to render pages: render of "page" failed: "/home/micro/testing/hugo-forum-topic-45500/layouts/_default/baseof.html:2:15": execute of template failed: template: tests/single.html:2:15: executing "tests/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Built in 6 ms