diff options
author | Bivectorfoil <550282600@qq.com> | 2018-10-12 15:19:10 +0300 |
---|---|---|
committer | coderzh <pythonzh@qq.com> | 2018-10-13 11:29:00 +0300 |
commit | 4a3e22f79bb09b676ee6515ccf2ad2c5150d9ad5 (patch) | |
tree | 3d909051713c72223a09dc42212852ed5f986aa1 | |
parent | 39c82a5fd7c87bfab74272dad78567018d6f6041 (diff) |
Add detection for loading Disqus
-rw-r--r-- | layouts/partials/comment.html | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/layouts/partials/comment.html b/layouts/partials/comment.html index 693642e..5631276 100644 --- a/layouts/partials/comment.html +++ b/layouts/partials/comment.html @@ -21,6 +21,12 @@ var duoshuoQuery = {short_name:"{{ .Site.Params.DuoShuo.ShortName }}"}; <div id="disqus_thread"></div> </section> <script> + <!-- detect whether Disuqs can load --> + var xhr = new XMLHttpRequest(); + xhr.open('GET', '//disqus.com/next/config.json?' + new Date().getTime(), true); + xhr.timeout = 3000; // 3 seconds timeout limit, as so far + + xhr.onload = function() { // set event handle function /** * RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS. * LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables @@ -37,6 +43,12 @@ s.src = '//{{ .Site.Params.Disqus.ShortName }}.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })(); +} + xhr.ontimeout = function() { + <!-- cannot load Disqus, skip it. --> + return; +} +xhr.send(null); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript> {{ end }} |