yannesposito.com/Scratch/fr/blog/11_Load_Disqus_Asynchronously/index.html
2013-03-16 09:31:39 +01:00

152 lines
8.7 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>YBlog - Load Disqus Asynchronously [en]</title>
<meta name="keywords" content="disqus, web, javascript, intense debate, commentaires">
<link rel="shortcut icon" type="image/x-icon" href="../../../../Scratch/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../../../Scratch/css/scientific.css" />
<link rel="stylesheet" type="text/css" href="../../../../Scratch/css/solarized.css" />
<!-- Font -->
<link href="http://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Droid+Sans:400,700" rel="stylesheet" type="text/css">
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.com/yannespositocomfr" />
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
</head>
<body lang="fr">
<script type="text/javascript">//
document.write('<div id="blackpage"><div>Bientôt<img src="/Scratch/img/loading.gif" alt="Chargement en cours"></img></div></div>');
//
</script>
<div id="content">
<div id="header">
<div id="choix">
<div id="choixlang">
<a href="../../../../Scratch/en/blog/11_Load_Disqus_Asynchronously" onclick="setLanguage('en')">
English </a>
</div>
<script type="text/javascript">//
document.write('<div id="switchcss"><a href="#">Changer de theme</a></div>');
//
</script>
<div class="tomenu"><a href="#navigation">↓ Menu ↓</a></div>
<div class="flush"></div>
</div>
</div>
<div id="titre">
<h1>Load Disqus Asynchronously [en]</h1>
</div>
<div class="flush"></div>
<div id="afterheader" class="article">
<div class="corps">
<h1 id="update">Update</h1>
<p>In fact this method works for old threads. But it fails to create new post threads. This is why I tried and be conquered by <a href="http://intensedebate.com">intensedebate</a>, as you can see in the bottom of this page.</p>
<p>Remark I didnt have any comment on my blog when I switched. Therefore my lack of influence was a good thing :-).</p>
<hr />
<p>Before begining, I must state that I <strong>love</strong> Disqus.</p>
<p>I know there is a similar blog entry at <a href="http://trephine.org/t/index.php?title=Site_improvements_-_fighting_with_Disqus">Trephine.org</a>. Here I just add a straight and easy way to load disqus asynchronously using jQuery.</p>
<p>I also know there is a jQuery plugin to make just that. Unfortunately I had some issue with CSS.</p>
<p><em>Now lets begin.</em></p>
<hr />
<h1 id="why">Why?</h1>
<p>Why should I want to load the disqus javascript asynchronously?</p>
<ul>
<li>Efficiency: I dont want my page to wait the complete execution of disqus script to load.</li>
<li>More independance: when disqus is down, my page is blocked!</li>
</ul>
<hr />
<h1 id="how">How?</h1>
<p>I give a solution with jQuery, but Im certain it will work with many other js library.</p>
<h3 id="javascript">Javascript</h3>
<p>replace:</p>
<div>
<pre class="sourceCode javascript"><code class="sourceCode javascript">&lt;script type=<span class="st">&quot;text/javascript&quot;</span> src=<span class="st">&quot;http://disqus.com/forums/YOUR_DISQUS_ID/embed.js&quot;</span>&gt;&lt;<span class="ot">/script&gt;</span></code></pre>
</div>
<p>by</p>
<div>
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="ot">window</span>.<span class="fu">disqus_no_style</span>=<span class="kw">true</span>;
<span class="fu">$</span>(document).<span class="fu">ready</span>(<span class="kw">function</span>(){
<span class="ot">$</span>.<span class="fu">getScript</span>(<span class="st">&quot;http://disqus.com/forums/YOUR_DISQUS_ID/embed.js&quot;</span>);
});</code></pre>
</div>
<p>If you forget the <code>window.disqus_no_style=true;</code> then your page will be blank. Simply because without this option, the javascript use a <code>document.write</code> action after the document was closed, which cause a complete erasing of it.</p>
<h3 id="css">CSS</h3>
<p>But with this option you still need to provide a CSS. This is why you have to copy the css code from the <code>embed.js</code> file and rewrite it in a CSS file. You can <a href="../../../../Scratch/en/blog/11_Load_Disqus_Asynchronously/code/original_disqus.css">download the CSS</a> I obtained.</p>
<hr />
<p>Now its done. I believe all should be fine but I just finished the manip for my own site only 1 hour ago. Therefore there should be some error, tell me if it is the case.</p>
</div>
<div id="social">
<a target="_blank" href="http://feeds.feedburner.com/yannespositocomfr" class="social">r</a>
·
<a target="_blank" href="https://twitter.com/home?status=http://yannesposito.com/Scratch/fr/blog/11_Load_Disqus_Asynchronously/index.html%22via%22@yogsototh" class="social">t</a>
·
<a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=/Scratch/fr/blog/11_Load_Disqus_Asynchronously" class="social">`</a>
·
<a target="_blank" href="https://plus.google.com/share?url=http://yannesposito.com/Scratch/fr/blog/11_Load_Disqus_Asynchronously" class="social">g</a>
<br />
<a class="message" href="../../../../Scratch/fr/blog/Social-link-the-right-way/">Ces liens sociaux préservent votre vie privée</a>
</div>
<div id="navigation">
<a href="../../../../">Home</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/blog">Blog</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/softwares">Softwares</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/about">About</a>
</div>
<div id="totop"><a href="#header">↑ Top ↑</a></div>
<div class="corps" id="comment">
<h2 class="first">Comments</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'yannesposito'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
<div class="tomenu"><a href="#navigation">↑ Menu ↑</a></div>
<div id="bottom">
<div>
Published on 2009-09-17
</div>
<div>
<a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
</div>
<div>
Yann Esposito©
</div>
<div>
Done with
<a href="http://www.vim.org">Vim</a>
<span class="nicer">&amp;</span>
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="../../../../Scratch/js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="../../../../Scratch/js/jquery.cookie.js"></script>
<script type="text/javascript" src="../../../../Scratch/js/index.js"></script>
<script type="text/javascript" src="../../../../Scratch/js/highlight/highlight.pack.js"></script>
<script type="text/javascript" src="../../../../Scratch/js/article.js"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</html>