Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use jsonp to get javascript based ad calls onto a page, asyncronously
    text
    copied!<p>I am trying to use jsonp to solve a page performance problem I've been having. On my site I usually display ads by writing out a script tag like this <code>document.write("&lt;scr" + "ipt src='advendor.com\myad.php'&gt;&lt;/scr" + "ipt&gt;");</code>. This is all well and good except for the fact that the sites the script tags point to have a nasty habit of being very slow. So when I have a page with 5 ads on it it can hold up my entire pages load time due to blocking from syncronous requests.</p> <p>So my idea was to make a jsonp call to the ad service which will give me the script tag that needs to be written to the page. The problem there is I get the <code>&lt;script&gt;</code> tag on the page but, the script tag does nothing. Will the script only work if it is written before document.ready?</p> <p>CLARIFICATION: Currently we have our server side code making calls to an ad serving system so it determines what ad code I get server side(in this a script tag with a "src=" that points to the vendors site, which generates the actual ad and tracking). What I'm trying to do is stop the ad calls from blocking the loading of my content. So I want content first and then all the ads next. Putting the script tags at the bottom of the page is not an acceptable solution because I need to determine where the ads appear on the page. IE, <code>&lt;div id="adOneHere"&gt;&lt;script src="vendorssite.com"&gt;&lt;/script&gt;&lt;/div&gt;</code>, I can have as many as five of these ad calls on one page. Each has its own images/tracking/etc...</p> <p>My problem is similar to the one addressed <a href="https://stackoverflow.com/questions/1934470/dynamic-script-tag-loading-is-not-working-as-expected">here</a>, except that I need to get the "script" tag from a centralized server from multiple domains, and I need to do the document.write inside a specific dom element, I'm well versed in jQuery if that helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload