-3

I have a Javascript code which shows kind of seal on site, here is the code

<script type="text/javascript" id="foo" src="https://www.rapidscansecure.com/siteseal/siteseal.js?code=[companyidcode]" ></script>

this impact on website insight score, I just want to execute this after few second of page load completed.

defer and async already used and not working

2 Answers2

1

Add defer attribute to the <script>.

The script is downloaded in background. And the script is executed once the browser is free after all the HTML document has been parsed.

<script type="text/javascript" id="foo" src="https://flaviocopes.com/javascript-async-defer/" defer></script>

Edit: The script is still executed before the DOMContentLoaded, but after DOM parsing.

Tushar Shahi
  • 16,452
  • 1
  • 18
  • 39
  • This is not an accurate answer, because defer download the script parallelly and run after the dom is parsed and before `DOMContentLoaded` event. Browser is free when everything is done in the background and dom parsed and all scripts loaded and executed. – DecPK Jul 13 '21 at 11:45
  • I have already used defer and async, but does not work – Frontend Dev Web Accessibility Jul 13 '21 at 11:53
1

Try Using document.onload = function ..

See this Question How to make JavaScript execute after page load?

execute function after complete page load

StarLight
  • 41
  • 6