Lazy load for "magnific.popup.js"

261 Views Asked by At

Is there a way of initializing the magnific.popup.js after the page loads?

I do not prefer loading it with the rest of the scripts as I only need it, and trigger the popup on a button click.

The ultimate goal is to not see it listed on the report of PageSpeed Insights, what would be your suggestion?

1

There are 1 best solutions below

2
ysrkaanky On

You can add your script dynamically.

function **functionname**(){   
    var script = document.createElement('script');
    
    script.setAttribute('src',**path or url script**);
    
    document.head.appendChild(script);
}

Call the function as you need the script