robertgombos
robertgombos

Reputation: 27

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!

Upvotes: 0

Views: 58

Answers (2)

Barmar
Barmar

Reputation: 780723

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.

Upvotes: 4

kawadhiya21
kawadhiya21

Reputation: 2528

If you are using Javascript, window.onload will do the job.

Upvotes: 0

Related Questions