Hello. I have a few ACF blocks an 3 of them use the swiper slider. Now I have the problem that swiper-bundle.min.js loads 3 times when I used all 3 blocks on a page. How can I prevent this? Here is a block.json from one of the blocks.
{
"$schema": "https://advancedcustomfields.com/schemas/json/main/block.json",
"name": "home-slider",
"title": "Slider",
"description": "Slider für die Startseite",
"category": "cdh",
"icon": "star-filled",
"keywords": ["slider", ""],
"styles": [],
"acf": {
"mode": "preview",
"renderTemplate": "home-slider.php"
},
"supports": {
"align": false,
"anchor": true
},
"editorStyle": "file:./style/home-slider-editor.css",
"script": ["file:./home-slider.js", "file:./swiper-bundle.min.js"],
"editorScript": "file:./home-slider.js",
"viewScript": ["file:./home-slider.js", "file:./swiper-bundle.min.js"],
"style": ["file:./style/home-slider.css","file:./style/swiper-bundle.min.css" ]
}
Heres the block.asset.php
<?php
return array(
'dependencies' => array(
'jquery',
'swiper',
),
'version' => '1.0.0',
);
I want the required scripts for the blocks to only be loaded if it hasn’t been loaded yet.