# テーマコンポーネントにライブラリをロードする方法

**URL:** <https://meta.discourse.org/t/how-to-load-library-in-a-theme-component/276621>\
**Category:** Development\
**Created:** [2023 年 8 月 25 日午後 2:54 UTC](https://meta.discourse.org/t/how-to-load-library-in-a-theme-component/276621 "2023-08-25T14:54:17Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2023 年 8 月 25 日午後 3:17 UTC](https://meta.discourse.org/t/how-to-load-library-in-a-theme-component/276621/5 "2023-08-25T15:17:39Z")

</div>

私の2つの主なアドバイスは次のとおりです。

### ライブラリをassetsフォルダに配置する

これによりCSPが解決され、テーマが自己完結型になり、サードパーティから読み込むのではなく、良い習慣と見なされます。

### 遅延読み込みする

必要になったときにのみ、`await loadScript`を使用して遅延読み込みできます。これにより、必要のないページでは読み込まれず、サイト全体の速度が低下することはありません。

* * *

これらの良い実践に従っているテーマの良い例は、[https://github.com/discourse/discourse-mermaid-theme-componentです。](https://github.com/discourse/discourse-mermaid-theme-component%E3%81%A7%E3%81%99%E3%80%82)

---

_[View the full topic](https://meta.discourse.org/t/how-to-load-library-in-a-theme-component/276621)._
