Skip to content

Instantly share code, notes, and snippets.

@ardianta
Last active May 13, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardianta/2cffbc578d73aea1ce0a87f65f0e5822 to your computer and use it in GitHub Desktop.
Save ardianta/2cffbc578d73aea1ce0a87f65f0e5822 to your computer and use it in GitHub Desktop.
Disqus Lazyloading using IntersectionObserver
<div id="disqus_thread">Loading Comments...</div>
<script>
var disqus_config = function () {
this.page.url = "https://www.petanikode.com/flutter-web";
this.page.identifier = "flutter-web";
this.page.title = "Tutorial Membuat Web dengan Flutter";
};
</script>
document.addEventListener("DOMContentLoaded", function () {
let disqusThread = document.querySelector("#disqus_thread");
if ("IntersectionObserver" in window) {
if (disqusThread != null) {
new IntersectionObserver((entries, observe) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
let d = document, s = d.createElement('script');
s.src = '//petanikode.disqus.com/embed.js';
s.async = true;
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
observe.unobserve(entry.target);
}
});
}).observe(disqusThread);
}
} else {
// Possibly fall back to a more compatible method here
console.log("Browser Not supported, plase upgrade!");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment