Adding freemarker to head from within a component
I have some custom components that need external javascript libraries.
For performance reasons, I want to start downloading the library when <head> tag renders, but the component that needs the js library is deep down in the component hierarchy.
At this time I have to resort to putting <script> or <link preload> or <link preconnect> tags in the head and then execute the javascript in the component.
Ideally I would want the component to contain all the code that is required for it to work including download/preloading/preconnecting scripts. Is that at all possible?
Note: Using javascript in the component to dynamically add the <script> tag in the <head> doesn't solve the problem because it will start download only when parsing html body. Placing it early in the download queue results in a performance boost, but the only way to achieve that is to have the <script><preload><preconnect> tags in the <head> come from the server side. (as far as I know).
Khoros Communities