From 5c6a8974018fa2e5e0220c3d19265532c6a8bb09 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Fri, 13 Oct 2017 03:13:11 +0800 Subject: [PATCH] Optimize Disqus to make DCL happen sooner --- _includes/2017/comments-area.html | 2 -- _js/behaviors/disqus.js | 6 +++++- _js/helpers/inject_disqus.js | 20 +++++++++++++++++--- assets/packed/app.js | 4 ++-- package.json | 2 +- yarn.lock | 6 +++--- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/_includes/2017/comments-area.html b/_includes/2017/comments-area.html index 3be8532c3..9e0910121 100644 --- a/_includes/2017/comments-area.html +++ b/_includes/2017/comments-area.html @@ -19,6 +19,4 @@ - - {% endif %} diff --git a/_js/behaviors/disqus.js b/_js/behaviors/disqus.js index b0d8c0c65..36de6d244 100644 --- a/_js/behaviors/disqus.js +++ b/_js/behaviors/disqus.js @@ -1,5 +1,6 @@ import onmount from 'onmount' import injectDisqus from '../helpers/inject_disqus' +import ready from 'dom101/ready' /** * Injects Disqus onto the page. @@ -13,5 +14,8 @@ onmount('[data-js-disqus]', function () { this.page.identifier = data.identifier } - injectDisqus(data.host) + // Disqus takes a while to load, don't do it so eagerly. + ready(() => { + injectDisqus(data.host) + }) }) diff --git a/_js/helpers/inject_disqus.js b/_js/helpers/inject_disqus.js index a5140712d..886b15faa 100644 --- a/_js/helpers/inject_disqus.js +++ b/_js/helpers/inject_disqus.js @@ -2,13 +2,27 @@ * Injects disqus's scripts into the page. * * @example - * injectDisqus('devhints.disqus.com') + * inject('devhints.disqus.com') */ -export default function injectDisqus (host) { +export default function inject (host) { + injectEmbed(host) + injectCount(host) +} + +export function injectEmbed (host) { const d = document const s = d.createElement('script') - s.src = 'https://' + host + '/embed.js' + s.src = `https://${host}/embed.js` s.setAttribute('data-timestamp', +new Date()) ;(d.head || d.body).appendChild(s) } + +export function injectCount (host) { + const d = document + const s = d.createElement('script') + s.src = `https://${host}/count.js` + s.id = 'dsq-count-scr' + s.async = true + ;(d.head || d.body).appendChild(s) +} diff --git a/assets/packed/app.js b/assets/packed/app.js index 1fe3c41d7..0263503b3 100644 --- a/assets/packed/app.js +++ b/assets/packed/app.js @@ -1,4 +1,4 @@ -webpackJsonp([0],{"/k7tj9kxRFhFtZjlt346":function(t,e,i){"use strict";function n(t,e){if(window.localStorage){var i=JSON.parse(window.localStorage[t]||"{}");i=e(i),window.localStorage[t]=JSON.stringify(i)}}function o(t){if(window.localStorage)return JSON.parse(window.localStorage[t]||"{}")}Object.defineProperty(e,"__esModule",{value:!0}),e.update=n,e.fetch=o},"/n6t+V4ehwYkVVtDRmGr":function(t,e,i){"use strict";function n(t){o((0,s.default)(t),{tag:"h2",wrapper:'
',body:'
'}).each(function(){o((0,s.default)(this).children("[data-js-h3-section-list]"),{tag:"h3",wrapper:'
',body:'
'})})}function o(t,e){function i(t,e,i){var n=(0,s.default)(o);n.addClass(t.attr("class")),t.before(n);var a=(0,s.default)(r);return a.addClass(t.attr("class")),a.append(i),e&&n.append(e),n.append(a),n}var n=e.tag,o=e.wrapper,r=e.body,a=t.children(":first-child"),u=(0,s.default)();if(!a.is(n)){var h=a.nextUntil(n);u=u.add(i(a,null,a.add(h)))}return t.children(n).each(function(){var t=(0,s.default)(this).nextUntil(n),e=(0,s.default)(this);u=u.add(i(e,e,t))}),u}Object.defineProperty(e,"__esModule",{value:!0}),e.default=n,e.groupify=o;var r=i("gCzbTwtZHf0SKa8ni0Jr"),s=function(t){return t&&t.__esModule?t:{default:t}}(r)},"2QOxTCxkuzN0PP2kJ2jn":function(t,e,i){"use strict";function n(t){s.update("dismissed",function(e){return e[t]=!0,e})}function o(t){var e=s.fetch("dismissed");return e&&e[t]}Object.defineProperty(e,"__esModule",{value:!0}),e.setDismissed=n,e.isDismissed=o;var r=i("/k7tj9kxRFhFtZjlt346"),s=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e.default=t,e}(r)},"2tov+8o2NrZdw/Lg8JZA":function(t,e,i){function n(t){return i(o(t))}function o(t){var e=r[t];if(!(e+1))throw new Error("Cannot find module '"+t+"'.");return e}var r={"./onmount.js":"6hLKOGpXaWUwTDQA5TL2"};n.keys=function(){return Object.keys(r)},n.resolve=o,t.exports=n,n.id="2tov+8o2NrZdw/Lg8JZA"},"6hLKOGpXaWUwTDQA5TL2":function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("/n6t+V4ehwYkVVtDRmGr"),r=n(o),s=i("tqbVxj9+xGAhlFrQpyTS"),a=n(s),u=i("yfX/NEeqeNrvWENPWWKS"),h=n(u);(0,a.default)(function(){var t=document.querySelector("[data-js-main-body]");t&&(0,r.default)(t),setTimeout(function(){(0,h.default)()})})},"BF4TFfJ+K+wsuHfLZ/S3":function(t,e,i){"use strict";function n(){return-1!==window.location.search.indexOf("preview=1")}Object.defineProperty(e,"__esModule",{value:!0}),e.isPreview=n},BuWMdGeXUEK0GmkN01pU:function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("yfX/NEeqeNrvWENPWWKS"),r=n(o),s=i("cYqQDyTPtD7lV79ovj4Y"),a=n(s);(0,r.default)("[data-js-disqus]",function(){var t=JSON.parse(this.getAttribute("data-js-disqus"));window.disqus_config=function(){this.page.url=t.url,this.page.identifier=t.identifier},(0,a.default)(t.host)})},C2mk7N9JzKWlcOYJrkfi:function(t,e){function i(t,e){var i=t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||t.oMatchesSelector;if(i)return i.call(t,e);if(t.parentNode){for(var n=t.parentNode.querySelectorAll(e),o=n.length;o--;0)if(n[o]===t)return!0;return!1}}t.exports=i},"CjZN/azBHJxH2NsOjfdD":function(t,e,i){"use strict";function n(t,e,i){return void 0!==i?o(t,e):r(t,e,i)}function o(t,e){var i=t.getAttribute("data-"+e);return JSON.parse(i||"{}")}function r(t,e,i){t.setAttribute("data-"+e,JSON.stringify(i))}Object.defineProperty(e,"__esModule",{value:!0}),e.data=n,e.getData=o,e.setData=r},"D3SYMdNAenu80VOO7/Dv":function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("yfX/NEeqeNrvWENPWWKS"),r=n(o),s=i("MKJaVdnD9jF7rk6rW6AJ"),a=n(s);(0,r.default)("[data-js-search-form]",function(){(0,a.default)(this,"submit",function(t){t.preventDefault();var e=document.querySelector("a[data-search-index]:visible"),i=e&&e.getAttribute("href");i&&(window.location=i)})})},DfTyEU8lscjHXmCMlptO:function(t,e,i){"use strict";function n(){(0,a.default)("[data-search-index]").forEach(function(t){t.removeAttribute("aria-hidden")})}function o(t){var e=(0,r.splitwords)(t);if(!e.length)return n();var i=e.map(function(t){return"[data-search-index~="+JSON.stringify(t)+"]"}).join("");(0,a.default)("[data-search-index]").forEach(function(t){t.setAttribute("aria-hidden",!0)}),(0,a.default)(i).forEach(function(t){t.removeAttribute("aria-hidden")})}Object.defineProperty(e,"__esModule",{value:!0}),e.showAll=n,e.show=o;var r=i("GOdGag34TlRuHa2OZoh9"),s=i("EvxNxLK9yKFmn1U14Kvw"),a=function(t){return t&&t.__esModule?t:{default:t}}(s)},"E+dCGfS1pT5WowYv7jpv":function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("GbzL7C/QFmiBZDICkla+"),r=n(o),s=i("yfX/NEeqeNrvWENPWWKS"),a=n(s),u=i("MKJaVdnD9jF7rk6rW6AJ"),h=n(u),c=i("EvxNxLK9yKFmn1U14Kvw"),d=n(c);(0,a.default)("[data-js-h3-section-list]",function(){var t=new r.default(this,{itemSelector:".h3-section",transitionDuration:0});(0,d.default)("img",this).forEach(function(e){(0,h.default)(e,"load",function(){t.layout()})})})},EvxNxLK9yKFmn1U14Kvw:function(t,e){function i(t,e){return Array.prototype.slice.call((e||document).querySelectorAll(t))}t.exports=i},GOdGag34TlRuHa2OZoh9:function(t,e,i){"use strict";function n(t){var e=[];return t.slug&&(e=e.concat(o(t.slug))),t.category&&(e=e.concat(o(t.category))),e}function o(t){var e=[];return s(t).forEach(function(t){e=e.concat(r(t))}),e}function r(t){for(var e=[],i=t.length,n=1;n<=i;++n)e.push(t.substr(0,n));return e}function s(t){return t.toLowerCase().split(/[ \/\-_]/).filter(function(t){return t&&0!==t.length})}Object.defineProperty(e,"__esModule",{value:!0}),e.default=n,e.permutateString=o,e.permutateWord=r,e.splitwords=s},"GbzL7C/QFmiBZDICkla+":function(t,e,i){var n,o,r,s,a,n,u,h,c,d,n,f,n,l,p,n,m,n,l,v,n,l,g,n,l,y,n,l,_,n,l,b,n,l,w,n,o;/*! +webpackJsonp([0],{"/k7tj9kxRFhFtZjlt346":function(t,e,i){"use strict";function n(t,e){if(window.localStorage){var i=JSON.parse(window.localStorage[t]||"{}");i=e(i),window.localStorage[t]=JSON.stringify(i)}}function o(t){if(window.localStorage)return JSON.parse(window.localStorage[t]||"{}")}Object.defineProperty(e,"__esModule",{value:!0}),e.update=n,e.fetch=o},"/n6t+V4ehwYkVVtDRmGr":function(t,e,i){"use strict";function n(t){o((0,s.default)(t),{tag:"h2",wrapper:'
',body:'
'}).each(function(){o((0,s.default)(this).children("[data-js-h3-section-list]"),{tag:"h3",wrapper:'
',body:'
'})})}function o(t,e){function i(t,e,i){var n=(0,s.default)(o);n.addClass(t.attr("class")),t.before(n);var a=(0,s.default)(r);return a.addClass(t.attr("class")),a.append(i),e&&n.append(e),n.append(a),n}var n=e.tag,o=e.wrapper,r=e.body,a=t.children(":first-child"),u=(0,s.default)();if(!a.is(n)){var h=a.nextUntil(n);u=u.add(i(a,null,a.add(h)))}return t.children(n).each(function(){var t=(0,s.default)(this).nextUntil(n),e=(0,s.default)(this);u=u.add(i(e,e,t))}),u}Object.defineProperty(e,"__esModule",{value:!0}),e.default=n,e.groupify=o;var r=i("gCzbTwtZHf0SKa8ni0Jr"),s=function(t){return t&&t.__esModule?t:{default:t}}(r)},"2QOxTCxkuzN0PP2kJ2jn":function(t,e,i){"use strict";function n(t){s.update("dismissed",function(e){return e[t]=!0,e})}function o(t){var e=s.fetch("dismissed");return e&&e[t]}Object.defineProperty(e,"__esModule",{value:!0}),e.setDismissed=n,e.isDismissed=o;var r=i("/k7tj9kxRFhFtZjlt346"),s=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e.default=t,e}(r)},"2tov+8o2NrZdw/Lg8JZA":function(t,e,i){function n(t){return i(o(t))}function o(t){var e=r[t];if(!(e+1))throw new Error("Cannot find module '"+t+"'.");return e}var r={"./onmount.js":"6hLKOGpXaWUwTDQA5TL2"};n.keys=function(){return Object.keys(r)},n.resolve=o,t.exports=n,n.id="2tov+8o2NrZdw/Lg8JZA"},"6hLKOGpXaWUwTDQA5TL2":function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("/n6t+V4ehwYkVVtDRmGr"),r=n(o),s=i("tqbVxj9+xGAhlFrQpyTS"),a=n(s),u=i("yfX/NEeqeNrvWENPWWKS"),h=n(u);(0,a.default)(function(){var t=document.querySelector("[data-js-main-body]");t&&(0,r.default)(t),setTimeout(function(){(0,h.default)()})})},"BF4TFfJ+K+wsuHfLZ/S3":function(t,e,i){"use strict";function n(){return-1!==window.location.search.indexOf("preview=1")}Object.defineProperty(e,"__esModule",{value:!0}),e.isPreview=n},BuWMdGeXUEK0GmkN01pU:function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("yfX/NEeqeNrvWENPWWKS"),r=n(o),s=i("cYqQDyTPtD7lV79ovj4Y"),a=n(s),u=i("tqbVxj9+xGAhlFrQpyTS"),h=n(u);(0,r.default)("[data-js-disqus]",function(){var t=JSON.parse(this.getAttribute("data-js-disqus"));window.disqus_config=function(){this.page.url=t.url,this.page.identifier=t.identifier},(0,h.default)(function(){(0,a.default)(t.host)})})},C2mk7N9JzKWlcOYJrkfi:function(t,e){function i(t,e){var i=t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||t.oMatchesSelector;if(i)return i.call(t,e);if(t.parentNode){for(var n=t.parentNode.querySelectorAll(e),o=n.length;o--;0)if(n[o]===t)return!0;return!1}}t.exports=i},"CjZN/azBHJxH2NsOjfdD":function(t,e,i){"use strict";function n(t,e,i){return void 0!==i?o(t,e):r(t,e,i)}function o(t,e){var i=t.getAttribute("data-"+e);return JSON.parse(i||"{}")}function r(t,e,i){t.setAttribute("data-"+e,JSON.stringify(i))}Object.defineProperty(e,"__esModule",{value:!0}),e.data=n,e.getData=o,e.setData=r},"D3SYMdNAenu80VOO7/Dv":function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("yfX/NEeqeNrvWENPWWKS"),r=n(o),s=i("MKJaVdnD9jF7rk6rW6AJ"),a=n(s);(0,r.default)("[data-js-search-form]",function(){(0,a.default)(this,"submit",function(t){t.preventDefault();var e=document.querySelector("a[data-search-index]:visible"),i=e&&e.getAttribute("href");i&&(window.location=i)})})},DfTyEU8lscjHXmCMlptO:function(t,e,i){"use strict";function n(){(0,a.default)("[data-search-index]").forEach(function(t){t.removeAttribute("aria-hidden")})}function o(t){var e=(0,r.splitwords)(t);if(!e.length)return n();var i=e.map(function(t){return"[data-search-index~="+JSON.stringify(t)+"]"}).join("");(0,a.default)("[data-search-index]").forEach(function(t){t.setAttribute("aria-hidden",!0)}),(0,a.default)(i).forEach(function(t){t.removeAttribute("aria-hidden")})}Object.defineProperty(e,"__esModule",{value:!0}),e.showAll=n,e.show=o;var r=i("GOdGag34TlRuHa2OZoh9"),s=i("EvxNxLK9yKFmn1U14Kvw"),a=function(t){return t&&t.__esModule?t:{default:t}}(s)},"E+dCGfS1pT5WowYv7jpv":function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var o=i("GbzL7C/QFmiBZDICkla+"),r=n(o),s=i("yfX/NEeqeNrvWENPWWKS"),a=n(s),u=i("MKJaVdnD9jF7rk6rW6AJ"),h=n(u),c=i("EvxNxLK9yKFmn1U14Kvw"),d=n(c);(0,a.default)("[data-js-h3-section-list]",function(){var t=new r.default(this,{itemSelector:".h3-section",transitionDuration:0});(0,d.default)("img",this).forEach(function(e){(0,h.default)(e,"load",function(){t.layout()})})})},EvxNxLK9yKFmn1U14Kvw:function(t,e){function i(t,e){return Array.prototype.slice.call((e||document).querySelectorAll(t))}t.exports=i},GOdGag34TlRuHa2OZoh9:function(t,e,i){"use strict";function n(t){var e=[];return t.slug&&(e=e.concat(o(t.slug))),t.category&&(e=e.concat(o(t.category))),e}function o(t){var e=[];return s(t).forEach(function(t){e=e.concat(r(t))}),e}function r(t){for(var e=[],i=t.length,n=1;n<=i;++n)e.push(t.substr(0,n));return e}function s(t){return t.toLowerCase().split(/[ \/\-_]/).filter(function(t){return t&&0!==t.length})}Object.defineProperty(e,"__esModule",{value:!0}),e.default=n,e.permutateString=o,e.permutateWord=r,e.splitwords=s},"GbzL7C/QFmiBZDICkla+":function(t,e,i){var n,o,r,s,a,n,u,h,c,d,n,f,n,l,p,n,m,n,l,v,n,l,g,n,l,y,n,l,_,n,l,b,n,l,w,n,o;/*! * Isotope PACKAGED v3.0.4 * * Licensed GPLv3 for open source use @@ -38,4 +38,4 @@ function(t,i){n=[g,y],l=i,_="function"==typeof l?l.apply(e,n):l}(window,function * http://isotope.metafizzy.co * Copyright 2017 Metafizzy */ -function(i,r){n=[m,u,h,f,v,g,_,b,w],void 0!==(o=function(t,e,n,o,s,a){return r(i,t,e,n,o,s,a)}.apply(e,n))&&(t.exports=o)}(window,function(t,e,i,n,o,r,s){function a(t,e){return function(i,n){for(var o=0;oa||sa?1:-1)*h}}return 0}}var u=t.jQuery,h=String.prototype.trim?function(t){return t.trim()}:function(t){return t.replace(/^\s+|\s+$/g,"")},c=e.create("isotope",{layoutMode:"masonry",isJQueryFiltering:!0,sortAscending:!0});c.Item=r,c.LayoutMode=s;var d=c.prototype;d._create=function(){this.itemGUID=0,this._sorters={},this._getSorters(),e.prototype._create.call(this),this.modes={},this.filteredItems=this.items,this.sortHistory=["original-order"];for(var t in s.modes)this._initLayoutMode(t)},d.reloadItems=function(){this.itemGUID=0,e.prototype.reloadItems.call(this)},d._itemize=function(){for(var t=e.prototype._itemize.apply(this,arguments),i=0;i-1:t.indexOf(i)>-1}function a(t,e){p[t]||(p[t]=[]),p[t].push(e),f.push(e)}function u(t,i){var n=t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||t.oMatchesSelector;if(e.$)return e.$(t).is(i);if(n)return n.call(t,i);if(t.parentNode){for(var o=t.parentNode.querySelectorAll(i),r=o.length;r--;0)if(o[r]===t)return!0;return!1}}function h(t,e){var i,n=t.length;if(n===+n)for(i=0;ia||sa?1:-1)*h}}return 0}}var u=t.jQuery,h=String.prototype.trim?function(t){return t.trim()}:function(t){return t.replace(/^\s+|\s+$/g,"")},c=e.create("isotope",{layoutMode:"masonry",isJQueryFiltering:!0,sortAscending:!0});c.Item=r,c.LayoutMode=s;var d=c.prototype;d._create=function(){this.itemGUID=0,this._sorters={},this._getSorters(),e.prototype._create.call(this),this.modes={},this.filteredItems=this.items,this.sortHistory=["original-order"];for(var t in s.modes)this._initLayoutMode(t)},d.reloadItems=function(){this.itemGUID=0,e.prototype.reloadItems.call(this)},d._itemize=function(){for(var t=e.prototype._itemize.apply(this,arguments),i=0;i-1:t.indexOf(i)>-1}function a(t,e){p[t]||(p[t]=[]),p[t].push(e),f.push(e)}function u(t,i){var n=t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||t.oMatchesSelector;if(e.$)return e.$(t).is(i);if(n)return n.call(t,i);if(t.parentNode){for(var o=t.parentNode.querySelectorAll(i),r=o.length;r--;0)if(o[r]===t)return!0;return!1}}function h(t,e){var i,n=t.length;if(n===+n)for(i=0;i