Delay Disqus loading

This commit is contained in:
Rico Sta. Cruz 2017-10-20 07:38:50 +08:00
parent 85a9b154eb
commit 24641e264e
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
4 changed files with 16 additions and 4 deletions

View File

@ -13,10 +13,10 @@
<div class='comments-section'> <div class='comments-section'>
<div class='comments'> <div class='comments'>
<div id='disqus_thread'></div> <div id='disqus_thread'></div>
<noscript data-js-disqus='{"host":"{{ site.data.disqus.host }}","url":"{{ site.url }}/{{ identifier }}","identifier":"{{ identifier }}"}'></noscript>
</div> </div>
</div> </div>
</details> </details>
</div> </div>
<noscript data-js-disqus='{"host":"{{ site.data.disqus.host }}","url":"{{ site.url }}/{{ identifier }}","identifier":"{{ identifier }}"}'></noscript>
</section> </section>
{% endif %} {% endif %}

View File

@ -2,12 +2,21 @@ import onmount from 'onmount'
import injectDisqus from '../helpers/inject_disqus' import injectDisqus from '../helpers/inject_disqus'
import ready from 'dom101/ready' import ready from 'dom101/ready'
/**
* Delay disqus by some time. It's at the bottom of the page, there's no need
* for it to load fast. This will give more time to load more critical assets.
*/
const DISQUS_DELAY = 10 * 1000
/** /**
* Injects Disqus onto the page. * Injects Disqus onto the page.
*/ */
onmount('[data-js-disqus]', function () { onmount('[data-js-disqus]', function () {
const data = JSON.parse(this.getAttribute('data-js-disqus')) const data = JSON.parse(this.getAttribute('data-js-disqus'))
const $parent = this.parentNode
$parent.setAttribute('hidden', true)
window.disqus_config = function () { window.disqus_config = function () {
this.page.url = data.url this.page.url = data.url
@ -16,6 +25,9 @@ onmount('[data-js-disqus]', function () {
// Disqus takes a while to load, don't do it so eagerly. // Disqus takes a while to load, don't do it so eagerly.
ready(() => { ready(() => {
setTimeout(() => {
injectDisqus(data.host) injectDisqus(data.host)
$parent.removeAttribute('hidden')
}, DISQUS_DELAY)
}) })
}) })

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long