Last active
November 24, 2016 05:26
-
-
Save rawsh/d2abc6fd7c3730770d3f79a9a93aaeb9 to your computer and use it in GitHub Desktop.
Load disqus on scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="comments"> | |
<div id="disqus_thread"></div> | |
</div> | |
<script type="text/javascript" src="comments.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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