I am facing a weird Issue, I want to create a simple image carousel using splide.js! In the block-editor I show the images as a scrollable list via “overflow: scroll”. I’ve added the splide.min.js as dependency using the “script” option at block-level. For some reason it also loads the script inside the block-editor!
Another Question I have regarding script files is: Is there any possibility to conditionally load the scripts, meaning only load them when the block is used on that page. I think I read somewhere that it is possible with one of the newest WP-Features, which would be pretty cool because now all assets get loaded on every single page, which can lead to a very bloated site in my opinion!
Just double checked it and it seems that this doesn’t work for me. When I remove the script file from here it doesn’t get loaded on pages, where I don’t use that block. When the script file is linked here it get’s loaded on all pages!
@Wolfgang.Hartl is this a theme or plugin? If it is a theme and the JS file is included on one of the source template files in HTML, it will get enqueued in the theme. In such cases add Don’t export action to that script tag.
I’ve tried all that but it still get loaded. The template is set to “do not export”, the script itself is also set to “do not enqueue”, so it shouldn’t get loaded in my opinion, right?
I’ve tested to unlink it from the block action, and when I remove it there it doesn’t get loaded on the frontend any longer. So it’s really only available if I use it on the block level itself.
I’m gonna double-check again if it get’s loaded on any other page when I’m back on the pc. But on the index.html (which is the only html-template that get’s exported on that theme) it is definitely not set!