Answer the question
In order to leave comments, you need to log in
How to correctly connect an external JS library so that it is loaded only after the entire html page is loaded?
I use the google recaptcha JS library on my site, I noticed that because of it the page loading speed drops.
How to correctly connect an external JS google library so that it is loaded only after loading the entire html page and styles, speed up page loading so that all html and styles are loaded and only then the google library is connected?
Is it possible to include an external JS library on the onload event?
Now I have a link to the google library connected in this way:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
Answer the question
In order to leave comments, you need to log in
window.onload = function() {
const script = document.createElement('script');
script.src = 'https://www.google.com/recaptcha/api.js';
script.async = 1;
script.defer = 1;
document.body.append(script);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question