Load external javascript file onclick?

Hi all.

Does anyone know how to load an external JS script onclick?

It is a widget from a holiday booking and management software company that absolutely hammers my page speed if I load it with the page, or with async or defer.

I only want the script to run when a visitor clicks ‘Book Now’.

I really need to learn JS!

Thanks in advance.

you have to add an event listener on click, and on the callback create a script element with the src set to your external js script. Yep you really should learn basic JS, it will be really worth on the long run!