Add Custom Java Script and swiper library in EDS | Community
Skip to main content
New Participant
November 27, 2024
Solved

Add Custom Java Script and swiper library in EDS

  • November 27, 2024
  • 2 replies
  • 945 views

I am Trying to create module with swiper in EDS. HTML part i have done. But adding Custom Java script for the module and Swiper library is triggering error. Can anyone guide me how to add swiper and custom JS for my module in Edge Delivery service. 

Best answer by ShaileshBassi

Hi @mohamedvalith In EDS you can load any script, but the loading of the script will impact your Lighthouse if it is not loaded properly.

 

So, the ideal way to load the script will be withing the section i.e. loadDelayed, so that there is no blocking time for the LCP data.

 

Please refer to the github boilerplate https://github.com/adobe/aem-boilerplate/blob/main/scripts/scripts.js 

Thanks

2 replies

New Participant
July 15, 2025

first you can direct put script to head or you can load that at a time of block load

const loadSwiper = () => {
  return new Promise((resolve) => {
    if (window.Swiper) {
      resolve(window.Swiper);
    } else {
      const swiperCss = document.createElement("link");
      swiperCss.rel = "stylesheet";
      swiperCss.href =
      document.head.appendChild(swiperCss);

      const swiperScript = document.createElement("script");
      swiperScript.src =
      swiperScript.onload = () => resolve(window.Swiper);
      document.head.appendChild(swiperScript);
    }
  });
};
ShaileshBassi
ShaileshBassiAccepted solution
New Participant
November 27, 2024

Hi @mohamedvalith In EDS you can load any script, but the loading of the script will impact your Lighthouse if it is not loaded properly.

 

So, the ideal way to load the script will be withing the section i.e. loadDelayed, so that there is no blocking time for the LCP data.

 

Please refer to the github boilerplate https://github.com/adobe/aem-boilerplate/blob/main/scripts/scripts.js 

Thanks

New Participant
November 28, 2024

Thank you ShaileshBassi. It is very helpful and your suggestion working fine.