Including script tags in ACF blocks

I am creating a few custom blocks using ACF. I am trying to keep the amount of Javascript being loaded per page at a minimum.

I was thinking that the best way to do this would be to include script tags in my block blades since a block would only be loaded when used, correct?

I am coming from the world of Vue.JS where components hold your JS, Template and style. Are there possible pitfalls with using this approach? Is there a a better way to ensure only the needed JS pages are loaded?

You’re correct, It’ll only be loaded when the block is on the page.
To enqueue a large library e.g. slick when a certain block is on the page, you might consider this approach

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.