Skip to content

Instantly share code, notes, and snippets.

@rawsh
Last active November 24, 2016 05:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rawsh/d2abc6fd7c3730770d3f79a9a93aaeb9 to your computer and use it in GitHub Desktop.
Save rawsh/d2abc6fd7c3730770d3f79a9a93aaeb9 to your computer and use it in GitHub Desktop.
Load disqus on scroll
<div class="comments">
<div id="disqus_thread"></div>
</div>
<script type="text/javascript" src="comments.js"></script>
// Disqus is a giant turd when loading, even without any comments it slows your site down.
// This script loads disqus when you scroll to a certain div aka comments
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery.waypoints/2.0.5/waypoints.js"></script>
<script type="text/javascript">
var loaded = 0; // make sure its only loaded once
var disqus_shortname = "whatever"; // change this to your shortname
$('.comments').waypoint(function() {
if (loaded == 0) {
$.ajax({
type: "GET",
url: "http://" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
cache: true
});
loaded = 1;
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment