This might not be appropriate for your use case, but I found it useful to 
load the JS libraries I need using the extra_js template block - then 
everything in the page can rely on them being there. Of course, if the 
libraries take a long time to load or use humongous amounts of memory, that 
might be a non-starter.

Vinay
On Sunday, 16 April 2023 at 15:30:09 UTC+1 [email protected] wrote:

> This is probably more of a Javascript question than a Nikola one, but I 
> want to create a template shortcode that relies on a Javascript library. 
> The dirt simple approach is to just have a `<script src=xxx>` element in 
> the shortcode output, but that means that if I use the shortcode twice, 
> I'll be loading the library twice. And any initialisation I do will happen 
> twice, etc.
>
> Is there a good way to put some sort of "do this once per page" block into 
> a shortcode template, so that the actual shortcode logic can rely on it? 
> The alternative, I guess, is to write a shortcode plugin which adds stuff 
> to `site.template_hooks["extra_head"]`, but that seems like overkill here...
>
> Paul
>

-- 
You received this message because you are subscribed to the Google Groups 
"nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nikola-discuss/28ad6976-6b00-4cb9-b88d-3b6b11ca1742n%40googlegroups.com.

Reply via email to