Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is the <strong><a href="http://www.websiteoptimization.com/speed/tweak/defer/" rel="noreferrer"><code>defer</code> attribute</a></strong> you could put on script blocks to defer its execution until the page completes loading.</p> <pre><code>&lt;script src="myscript.js" type="text/javascript" defer&gt; // blah blah &lt;/script&gt; </code></pre> <p>I am not sure about the general recommendation about using this attribute though.</p> <p><strong>EDIT:</strong> As @David pointed out, use <code>defer="defer"</code> for XHTML</p> <p>And you can always put the code inside the <strong><code>window.onload</code></strong> event so that it executes <em>after</em> the pages load:</p> <pre><code>window.onload = function () { // ad codes here }; </code></pre> <p>But the later approach may pose some problems, you might want to test it out first.</p> <p>More information on <a href="http://dean.edwards.name/weblog/2005/09/busted/" rel="noreferrer">this blog post</a> by Dean Edwards, the guy who wrote the famous <a href="http://dean.edwards.name/packer/" rel="noreferrer">javascript packer</a>.</p> <hr> <p><strong>EDIT:</strong> If the size of ad code itself is the problem, you can always defer the loading by combining the above methods with script injection via <code>document.write</code>:</p> <pre><code>function loadScript(src) { document.write('&lt;script src="' + src + '" type="text/javascript"&gt;&lt;/script&gt;'); } </code></pre> <p>So the resulting code might look something like this:</p> <pre><code>&lt;script type="text/javascript" defer&gt; function loadScript(src) { document.write('&lt;script src="' + src + '" type="text/javascript"&gt;&lt;/script&gt;'); } loadScript('http://ads.example.com/advertisements.js'); &lt;/script&gt; </code></pre> <p>But as I've said, it depends on the specific ad code you get too. Because of the position <code>document.write</code> will write stuffs to might not be the location you want. Some modifications might be neccessary.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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