Earlier this month I took another look at what was required for reading an article on this site. What else could I do to make this site load faster?
To do this, I loaded up WebPageTest and pointed it towards one of my posts. To my shock, it took 113 requests for a total of 721 KB to load a single post. This took WebPageTest 6.491 seconds. The document complete event triggered after 15 requests (103 KB, 1.6 seconds).
113 requests to load a static article was ridiculous. Most of those requests happened as a result of loading the Disqus javascript. I find comments valuable and want to continue including them on my site. Because of this, I couldn’t remove Disqus. Instead, I made loading Disqus optional.
After making the required changes, it only takes 11 requests for 61 KB of data to fully load the test post. The document complete event only required 8 requests for 51 KB of data. Optionally loading the Disqus javascript resulted in a massive reduction of data transferred.
How did I do it? The template that generates my articles now only inserts the Disqus javascript when a reader clicks a button. My final template is at the bottom of this post.
The template adds an insertDisqus
function that inserts a <script>
element when a reader clicks a button. This element contains the original JavaScript that loads Disqus. When the <script>
element is inserted into the page, the Disqus javascript is loaded and the comments appear.
My exact template might not work for you, but I’d encourage you to think about optionally loading Disqus and other non-required JavaScript. Your readers will thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|