I'm trying to include clientlibs with async or defer attributes in the script tag. However, I also want to ensure that each clientlib is not loaded more than once. So if I include the clientlib within a component's code and the component is used multiple times on a page, the script tag should only appear in the first instance of the component.
The default way of including clientlibs (using /libs/granite/sightly/templates/clientlib.html) does seem to prevent the same script from being loaded more than once, but doesn't support async/defer.
I was able to get async/defer working using the https://github.com/nateyolles/aem-clientlib-async example that I've seen mentioned here. However, this code does not prevent the script from being loaded and executed multiple times if there are multiple components on the page.
Does anyone know how I might accomplish this? I would appreciate any insight!
Solved! Go to Solution.