简体   繁体   中英

Execute JS only after the entire page loaded

I am trying to optimize a piece of JS (it's a company details - address, phone number etc. verification badge). I really don't need it, but it pulls info from two different CDN's, which adds up to my page speed.

The line looks like this:

<script src="https://d20iczrsxk7wft.cloudfront.net/botwverified/badge.js?id=1234567"></script>

It is possible (jquery is already loaded for other stuff) to make this appear, or load, only after the page completely loaded? Probably JS? I know nothing about JS. My page loads in 1.5 second and this badge takes an extra second load.

Thank you!

You can use jQuery to load the script dynamically.

<script>
$(document).ready(function() {
    $.getScript("https://d20iczrsxk7wft.cloudfront.net/botwverified/badge.js?id=1234567");
});
</script>

The ready() function calls the function after the page is loaded.

如果您使用Javascript,则window.onload将完成此工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM