<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Sergio Mercado]]></title>
  <link href="http://smercadomx.github.io/atom.xml" rel="self"/>
  <link href="http://smercadomx.github.io/"/>
  <updated>2016-05-17T21:15:12-07:00</updated>
  <id>http://smercadomx.github.io/</id>
  <author>
    <name><![CDATA[Sergio Mercado]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[How to Load Ads Asynchronously]]></title>
    <link href="http://smercadomx.github.io/blog/2014/05/26/how-to-load-ads-asynchronously/"/>
    <updated>2014-05-26T12:54:12-07:00</updated>
    <id>http://smercadomx.github.io/blog/2014/05/26/how-to-load-ads-asynchronously</id>
    <content type="html"><![CDATA[<h2>The Problem</h2>

<p>Most ads come with document.write statements, and we all know what happens when we try to execute them after the page has been loaded.</p>

<h2>The Solution</h2>

<p>postscribe is a JS library that ensures the content is written as close to the way the browser would natively write the content with document.write/innerHTML, and it does it asynchronously!.</p>

<h2>The Implementation</h2>

<h3>HTML:</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;ad&quot;</span><span class="nt">&gt;</span><span class="c">&lt;!-- ad content will be written here --&gt;</span><span class="nt">&lt;/div&gt;</span>
</span><span class='line'>
</span><span class='line'><span class="c">&lt;!-- postscribe scripts --&gt;</span>
</span><span class='line'><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">&quot;htmlParser/htmlParser.js&quot;</span><span class="nt">&gt;&lt;/script&gt;</span>
</span><span class='line'><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">&quot;postscribe.js&quot;</span><span class="nt">&gt;&lt;/script&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<h3>JS:</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">win</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">adCode</span> <span class="o">=</span> <span class="s1">&#39;&lt;script&gt;document.write(&quot;ad unit&quot;);&lt;/script&gt;&#39;</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">postscribe</span><span class="p">(</span><span class="s1">&#39;#ad&#39;</span><span class="p">,</span> <span class="nx">adCode</span><span class="p">);</span>
</span><span class='line'><span class="p">}(</span><span class="nb">window</span><span class="p">));</span>
</span></code></pre></td></tr></table></div></figure>


<p>Simple, right?!</p>
]]></content>
  </entry>
  
</feed>
