javascript - Load all technorati script ads tags asynchronously -
what issue? have issue slow ads loading on webpage, technorati ad tags using blocking page rendering until advertising tags loads 1 one,
example: if have ad tag in middle of page, can't see footer of page until ad tag loads completely.
what need ? want method make page loads faster , keep these scripts after whole page loaded (asynchronous), tried multiple methods didn't work.
here's ad tag code have use:
<script type="text/javascript"> document.write('<scri' + 'pt type="text/javascript" src="' + (document.location.protocol == 'https:' ? 'https://uat-secure' : 'http://ad-cdn') + '.technoratimedia.com/00/81/95/uat_19581.js?ad_size=300x250"></scri' + 'pt>'); </script>
here's link page using ad tags on: http://feat.youmobile.org/
try using defer
or async
in generated script
tag, depending on intended behavior:
<script type="text/javascript"> document.write('<scri' + 'pt type="text/javascript" defer src="' + (document.location.protocol == 'https:' ? 'https://uat-secure' : 'http://ad-cdn') + '.technoratimedia.com/00/81/95/uat_19581.js?ad_size=300x250"></scri' + 'pt>'); </script>
update:
how writing once document has loaded? like:
<script type="text/javascript"> window.addeventlistener('domcontentloaded', function() { document.write('<scri' + 'pt type="text/javascript" defer src="' + (document.location.protocol == 'https:' ? 'https://uat-secure' : 'http://ad-cdn') + '.technoratimedia.com/00/81/95/uat_19581.js?ad_size=300x250"></scri' + 'pt>'); } </script>
you can use <body onload="writethescript()">
, depending on intention.
update 2:
that's because document.write overwriting content. try way:
<script type="text/javascript"> window.addeventlistener('domcontentloaded', function() { var scriptelement = document.createelement('script'); scriptelement.setattribute('src','' + (document.location.protocol == 'https:' ? 'https://uat-secure' : 'http://ad-cdn') + '.technoratimedia.com/00/81/95/uat_19581.js?ad_size=300x250'); scriptelement.setattribute('type', 'text/javascript'); document.body.appendchild(scriptelement); }); </script>
Comments
Post a Comment