<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title><![CDATA[Jake McCrary's articles on blog]]></title>
  <link href="https://jakemccrary.com/atom.xml" rel="self"/>
  <link href="https://jakemccrary.com/"/>
  <updated>2026-08-17T20:14:29+00:00</updated>
  <id>https://jakemccrary.com/</id>
  <author>
    <name><![CDATA[Jake McCrary]]></name>
  </author>
  <entry>
    <id>https://jakemccrary.com/blog/2017/06/30/speeding-up-site-by-optionally-loading-disqus-comments/index.html</id>
    <link href="https://jakemccrary.com/blog/2017/06/30/speeding-up-site-by-optionally-loading-disqus-comments/index.html"/>
    <title><![CDATA[Speeding up this site by optionally loading Disqus comments]]></title>
    <updated>2017-06-30T23:59:59+00:00</updated>
    <content type="html"><![CDATA[<div><p>Earlier this month I took another look at what was required for reading an article on this site. What <a href="/blog/2016/04/30/speeding-up-my-blog/">else</a> could I do to make this site load faster?</p><p>To do this, I loaded up <a href="http://webpagetest.org/">WebPageTest</a> and pointed it towards one of my <a href="/blog/2017/05/30/adding-a-json-feed-to-octopress-slash-jekyll/">posts</a>. 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).</p><p>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&apos;t remove Disqus. Instead, I made loading Disqus optional.</p><p>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.</p><p>How did I do it? The template that generates my articles now only inserts the Disqus javascript when a reader clicks a button. My <a href="https://github.com/jakemcc/jakemccrary.com/blob/74f4232ce7263ba3de48497d0c0d10a8fa1a73f9/source/_includes/disqus.html">final template</a> is at the bottom of this post.</p><p>The template adds an <code>insertDisqus</code> function that inserts a <code>&lt;script&gt;</code> element when a reader clicks a button. This element contains the original JavaScript that loads Disqus. When the <code>&lt;script&gt;</code> element is inserted into the page, the Disqus javascript is loaded and the comments appear.</p><p>My exact template might not work for you, but I&apos;d encourage you to think about optionally loading Disqus and other non-required JavaScript. Your readers will thank you.</p><pre><code class="language-html">{% if site.disqus_short_name and page.comments == true %}
  &lt;noscript&gt;Please enable JavaScript to view the &lt;a href=&quot;http://disqus.com/?ref_noscript&quot;&gt;comments powered by Disqus.&lt;/a&gt;&lt;/noscript&gt;
  &lt;div id=&quot;disqus_target&quot;&gt;
    &lt;script&gt;
     var insertDisqus = function() {
       var elem = document.createElement(&apos;script&apos;);
       elem.innerHTML =  &quot;var disqus_shortname = &apos;{{ site.disqus_short_name }}&apos;; var disqus_identifier = &apos;{{ site.url }}{{ page.url }}&apos;; var disqus_url = &apos;{{ site.url }}{{ page.url }}&apos;; (function () {var dsq = document.createElement(&apos;script&apos;); dsq.type = &apos;text/javascript&apos;; dsq.async = true; dsq.src = &apos;//&apos; + disqus_shortname + &apos;.disqus.com/embed.js&apos;; (document.getElementsByTagName(&apos;head&apos;)[0] || document.getElementsByTagName(&apos;body&apos;)[0]).appendChild(dsq);}());&quot;
       var target = document.getElementById(&apos;disqus_target&apos;);
       target.parentNode.replaceChild(elem, target);
     }
    &lt;/script&gt;
    &lt;button class=&quot;comment-button&quot; onclick=&quot;insertDisqus()&quot;&gt;&lt;span&gt;ENABLE COMMENTS AND RECOMMENDED ARTICLES&lt;/span&gt;&lt;/button&gt;
  &lt;/div&gt;
{% endif %}
</code></pre></div>]]></content>
  </entry>
  <entry>
    <id>https://jakemccrary.com/blog/2017/05/30/adding-a-json-feed-to-octopress-slash-jekyll/index.html</id>
    <link href="https://jakemccrary.com/blog/2017/05/30/adding-a-json-feed-to-octopress-slash-jekyll/index.html"/>
    <title><![CDATA[Adding a JSON Feed to an Octopress/Jekyll generated site]]></title>
    <updated>2017-05-30T23:59:59+00:00</updated>
    <content type="html"><![CDATA[<div><p>I went to a coffee shop this last weekend with the intention of writing up a <a href="/blog/2017/05/29/using-comm-to-verify-matching-content/">quick article</a> on <code>comm</code>. I sat down, sipping my coffee, and wasn’t motivated. I didn’t feel like knocking out a short post, and I didn’t feel like editing a draft I’ve been sitting on for a while. I wanted to do some work though, so I decided to add a <a href="https://jsonfeed.org/">JSON Feed</a> to this site.</p><p>JSON Feed is an alternative to <a href="https://tools.ietf.org/html/rfc4287">Atom</a> and <a href="http://cyber.harvard.edu/rss/rss.html">RSS</a> that uses JSON instead of XML. I figured I could add support for it in less than the time it would take to enjoy my coffee and maybe some readers would find it useful. I’d be shocked if anyone actually finds this useful, but it was a fun little exercise anyway.</p><p>An old version of Octopress (2.something), which uses an old version of Jekyll (2.5.3), generates this site. Despite this, I don’t think the template would need to change much if I moved to a new version. The template below is saved as <a href="https://github.com/jakemcc/jakemccrary.com/blob/00d4b0416ab2591be5702286b735091a3d2e2105/source/feed.json">source/feed.json</a> in my git repository.</p><pre><code class="language-javascript">---
layout: null
---
{
  &quot;version&quot;: &quot;https://jsonfeed.org/version/1&quot;,
  &quot;title&quot;: {{ site.title | jsonify }},
  &quot;home_page_url&quot;: &quot;{{ site.url }}&quot;,
  &quot;feed_url&quot;: &quot;{{site.url}}/feed.json&quot;,
  &quot;favicon&quot;: &quot;{{ site.url }}/favicon.png&quot;,
  &quot;author&quot; : {
      &quot;url&quot; : &quot;https://twitter.com/jakemcc&quot;,
      &quot;name&quot; : &quot;{{ site.author | strip_html }}&quot;
  },
  &quot;user_comment&quot;: &quot;This feed allows you to read the posts from this site in any feed reader that supports the JSON Feed format. To add this feed to your reader, copy the following URL - {{ site.url }}/feed.json - and add it your reader.&quot;,
  &quot;items&quot;: [{% for post in site.posts limit: 20 %}
    {
      &quot;id&quot;: &quot;{{ site.url }}{{ post.id }}&quot;,
      &quot;url&quot;: &quot;{{ site.url }}{{ post.url }}&quot;,
      &quot;date_published&quot;: &quot;{{ post.date | date_to_xmlschema }}&quot;,
      &quot;title&quot;: {% if site.titlecase %}{{ post.title | titlecase | jsonify }}{% else %}{{ post.title | jsonify }}{% endif %},
      {% if post.description %}&quot;summary&quot;: {{ post.description | jsonify }},{% endif %}
      &quot;content_html&quot;: {{ post.content | expand_urls: site.url | jsonify }},
      &quot;author&quot; : {
        &quot;name&quot; : &quot;{{ site.author | strip_html }}&quot;
      }
    }{% if forloop.last == false %},{% endif %}
    {% endfor %}
  ]
}
</code></pre><p>I approached this problem by reading the <a href="https://jsonfeed.org/version/1">JSON Feed Version 1 spec</a> and cribbing values from the template for my Atom feed. The trickiest part was filling in the <code>&quot;content_html&quot;</code> value. It took me a while to find figure out that <code>jsonify</code> needed to be at the end of <code>{{ post.content | expand_urls: site.url | jsonify }}</code>. That translates the post&apos;s HTML content into its JSON representation. You’ll notice that any template expression with <code>jsonify</code> at the end also isn’t wrapped in quotes. This is because <code>jsonify</code> is doing that for me.</p><p>The <code>{% if forloop.last == false %},{% endif %}</code> is also important. Without this, the generated JSON has an extra <code>,</code> after the final element in items. This isn’t valid JSON.</p><p>I caught that by using the command line tool <a href="http://trentm.com/json/">json</a>. If you ever edit JSON by hand or generate it from a template then you should add this tool to your toolbox. It will prevent you from creating invalid JSON.</p><p>How did I use it? I’d make a change in the <code>feed.json</code> template and generate an output file. Then I’d <code>cat</code> that file to <code>json --validate</code>. When there was an error, I’d see a message like below.</p><pre><code class="language-console">0 [last: 5s] 12:43:47 ~/src/jakemcc/blog (master *)
$ cat public/feed.json | json --validate
json: error: input is not JSON: Expected &apos;,&apos; instead of &apos;{&apos; at line 25, column 5:
            {
        ....^
1 [last: 0s] 12:43:49 ~/src/jakemcc/blog (master *)
$
</code></pre><p>And there would be zero output on success.</p><pre><code class="language-console">0 [last: 5s] 12:45:25 ~/src/jakemcc/blog (master)
$ cat public/feed.json | json --validate
0 [last: 0s] 12:45:30 ~/src/jakemcc/blog (master)
$
</code></pre><p>It was pretty straightforward to add a JSON Feed. Was it a good use of my time? <code>¯\_(ツ)_/¯</code>. In the process of adding the feed I learned more about Liquid templating and figured out how to embed liquid tags into a blog post. Even adding redundant features can be a useful exercise.</p></div>]]></content>
  </entry>
  <entry>
    <id>https://jakemccrary.com/blog/2016/10/28/html-markup-for-better-sharing-on-social-media/index.html</id>
    <link href="https://jakemccrary.com/blog/2016/10/28/html-markup-for-better-sharing-on-social-media/index.html"/>
    <title><![CDATA[HTML markup for better sharing on social media]]></title>
    <updated>2016-10-28T23:59:59+00:00</updated>
    <content type="html"><![CDATA[<div><p>For a bit more than a year I worked on a project that crawled the web and indexed articles. Two of our sources of data were articles shared on Facebook and Twitter. After seeing hundreds of article previews on these two social networks, I decided to improve how my own articles were previewed.</p><p>I thought figuring out the markup I needed to add would be a painless experience. Unfortunately, when you search for this information you end up at various SEO optimization and other similar sites where you get the pleasure of experiencing full screen pop-overs trying to get you to sign up for mailing lists and other annoying features of the modern web. Probably unsurprisingly, the least annoying source for this information turned out to be the social networks themselves.</p><p>Below is what you will want to add to the <code>&lt;head&gt;</code> section of your articles&apos; markup. Items in all caps should be values that make sense for your articles. Most fields are pretty self-evident, but check <a href="https://dev.twitter.com/cards/markup">Twitter&apos;s</a> and <a href="https://developers.facebook.com/docs/sharing/webmasters#markup">Facebook&apos;s</a> documentation for more details. The <a href="http://ogp.me/">Open Graph</a> documentation has more details as well.</p><pre><code class="language-html">&lt;!-- Twitter Card data --&gt;
&lt;meta name=&quot;twitter:card&quot; content=&quot;SUMMARY&quot; /&gt;
&lt;meta name=&quot;twitter:site&quot; content=&quot;TWITTER HANDLE OF SITE (@jakemcc for this site)&quot; /&gt;
&lt;meta name=&quot;twitter:creator&quot; content=&quot;YOUR TWITTER HANDLE&quot; /&gt;
&lt;meta name=&quot;twitter:title&quot; content=&quot;ARTICLE TITLE&quot; /&gt;
&lt;meta name=&quot;twitter:description&quot; content=&quot;SHORT DESCRIPTION OF CONTENT&quot; /&gt;
&lt;meta name=&quot;twitter:image&quot; content=&quot;IMAGE THAT SHOWS UP WITH PREVIEW&quot; /&gt;

&lt;!-- Open Graph data --&gt;
&lt;meta property=&quot;og:site_name&quot; content=&quot;SITE TITLE&quot; /&gt;
&lt;meta property=&quot;og:url&quot; content=&quot;CANONICAL URL&quot; /&gt;
&lt;meta property=&quot;og:title&quot; content=&quot;ARTICLE TITLE&quot; /&gt;
&lt;meta property=&quot;og:description&quot; content=&quot;SHORT DESCRIPTION OF CONTENT&quot; /&gt;
&lt;meta property=&quot;og:image&quot; content=&quot;IMAGE THAT SHOWS UP WITH PREVIEW&quot; /&gt;
&lt;meta property=&quot;og:type&quot; content=&quot;article&quot; /&gt;
&lt;meta property=&quot;article:published_time&quot; content=&quot;PUBLISHED DATETIME&quot; /&gt;
</code></pre><p>If you have control of your site&apos;s markup and want better previews of your articles on the various social networks then you should add this markup to your web site <a href="#fn-1" id="fnref1"><sup>1</sup></a>. Hopefully this article has saved you from having a full screen pop-over prompt you to join yet another mailing list.</p><ol class="footnotes"><li class="footnote" id="fn-1"><p>You can actually remove the <code>twitter:title</code>, <code>twitter:description</code>, and <code>twitter:image</code> lines since Twitter will fallback to the equivalent Open Graph markup if they missing.<a href="#fnref1">↩</a></p></li></ol></div>]]></content>
  </entry>
  <entry>
    <id>https://jakemccrary.com/blog/2016/04/30/speeding-up-my-blog/index.html</id>
    <link href="https://jakemccrary.com/blog/2016/04/30/speeding-up-my-blog/index.html"/>
    <title><![CDATA[Speeding up my blog]]></title>
    <updated>2016-04-30T23:59:59+00:00</updated>
    <content type="html"><![CDATA[<div><p>I was recently reading <a href="https://jefframnani.com/about/">Jeff Ramnani&apos;s</a> <em>about</em> page and I was somewhat inspired by it. It loads quickly and links to <a href="http://mattgemmell.com/designing-blogs-for-readers/">Designing blogs for readers</a>, an interesting essay by Matt Gemmmell. Reading that essay inspired me to think about my own site and what experience I want to deliver to readers.</p><p>I can&apos;t imagine what every reader wants but I know what I want to experience when I read an article online. Reading high quality content is my highest priority. Beyond that I enjoy when a page loads fast and the visual design doesn&apos;t get in the way. I think a great example of these two requirements is <a href="http://zenhabits.net/falling/">zen habits</a> (along with Jeff Ramnani&apos;s and Matt Gemmell&apos;s).</p><p>My own site sort of achieves those goals. I like to think I&apos;m writing well-written content that helps others. I know it has helped me. With regards to visual design I think there is room for improvement. I don&apos;t think my site&apos;s design is actively distracting from the content though, so I&apos;ve decided to focus on improving the page load time first.</p><h2 id="the-optimization-process">The optimization process</h2><p>As with any optimization problem it is important figure what you&apos;re going to measure, how you&apos;re going to measure it and your starting point. I decided to focus on my page load time, as measured by <a href="http://www.webpagetest.org">Web Page Test</a>. I used Google&apos;s <a href="https://developers.google.com/speed/pagespeed/insights/">PageSpeed Insights</a> to score and provide helpful tips for improving page speed. Unfortunately I didn&apos;t capture my starting point with PageSpeed Insights but I think I was scoring around a 66/100 for mobile and 79/100 for desktop.</p><p><img alt="Starting point from Web Page Test" src="/images/before-optimizations.png" /></p><p>As measured by Web Page Test, the first load of my main page took five seconds and it wasn&apos;t fully loaded for another second. This is ridiculous. My page is almost entirely static content and most of my assets are served from CloudFlare. It should be blazing fast.</p><p>Next I looked at what was actually being loaded. Google&apos;s PageSpeed Insights identified that I had three render-blocking <code>script</code> tags. The offending scripts were Modernizr, jQuery, and octopress.js. PageSpeed Insights <a href="https://developers.google.com/speed/docs/insights/BlockingJS#overview">recommends</a> inlining JavaScript required to render the page or make loading asynchronous. I decided to go a step further and remove the need for the JavaScript.</p><h3 id="removing-octopress.js">Removing octopress.js</h3><p>It turns out <code>octopress.js</code> was the reason Modernizr and jQuery were required. Most of what <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js">octopress.js</a> did were things that I don&apos;t need; some sort of <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js#L111">flash video fallback</a>, adding line numbers to <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js#L112">GitHub Gists</a>, <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js#L99">rendering</a> delicious links, and toggling the <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js#L114">sidebar visibility</a>. I was able to delete all that code.</p><p>Next up was the <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js#L1-L13">mobile navigation</a> <code>octopress.js</code> provided. This feature enabled navigation through a <code>&lt;select&gt;</code> element when the reader&apos;s view port was tiny. Restyling my navigation bar to fit better on small screens allowed me to remove this feature. <code>ocotpress.js</code> also did some <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js#L37">feature detection</a> for Modernizr. I stopped using image masks and was able to remove that code as well.</p><p>The remaining code in <code>octopress.js</code> was a workaround for an <a href="https://github.com/jakemcc/jakemccrary.com/blob/c27a131aef437181dcab9552c3241f8adafb3884/source/javascripts/octopress.js#L121-L136">iOS scaling bug</a>. This JavaScript was inlined into my html. At this point <code>octopress.js</code> was empty and with it empty the requirements for jQuery and Modernizer disappeared. This let me remove three render-blocking <code>script</code> tags.</p><h3 id="remaining-javascript">Remaining JavaScript</h3><p>At this point the remaining JavaScript used for my blog was enabling comments with Disqus and showing recent tweets in my sidebar. I still enjoy having comments on my blog so I&apos;m keeping Disqus around. I doubt that readers care what my most recent tweets are so I removed Twitter&apos;s JavaScript. Removing my tweets also cleans up my sidebar and helps keep the focus on my writing.</p><h3 id="nearly-no-javascript,-now-what?">Nearly no JavaScript, now what?</h3><p>At this point Google&apos;s PageSpeed Insight was suggesting that I up my cache times, inline my css, and move my web fonts lower on my page. Bumping up my cache times was trivial; I simply tweaked a CloudFlare setting.</p><p>I opted to not inline my css. This would require me to modify my site&apos;s generation and I just didn&apos;t feel like diving down that rabbit hole. I also didn&apos;t move the web fonts lower on the page. I find fonts re-rendering jarring and as a result kept them loading<a href="#fn-0" id="fnref0"><sup>0</sup></a> in my <code>&lt;head&gt;</code>.</p><h2 id="the-results">The results</h2><p>I used Web Page Test to measure again and now the page load time is down to 2.5 seconds. Page load times are cut in half from the starting point. My PageSpeed Insights scores are also higher; up to 79/100 for mobile and 92/100 for desktop.</p><p><img alt="Web Page Test after optimization" src="/images/after-optimizations.png" /></p><p>Honestly, that number still seems high<a href="#fn-1" id="fnref1"><sup>1</sup></a> to me and I&apos;m sure I could get it lower. But for now it is good enough<a href="#fn-2" id="fnref2"><sup>2</sup></a>. As a result of doing this I&apos;ve learned more about my blogging setup and managed to speed up my page load. Now it is time to focus on researching for future posts (and at some point restyling).</p><h2 id="update-on-2016-05-03">Update on 2016-05-03</h2><p>I completely removed web font loading from my site. Getting rid of the fonts reduced my load time, as measured by Web Page Test, by a second. Google&apos;s PageSpeed Insights now scores this site at 90/100 for mobile and 96/100 for desktop.</p><p><img alt="Web Page Test after font removal" src="/images/after-optimizations2.png" /></p><ol class="footnotes"><li class="footnote" id="fn-0"><p>When I first wrote this I didn&apos;t change anything about my web fonts. After thinking about it for a few days I ended up removing them completely. Details are in the update at the end of the post.<a href="#fnref0">↩</a></p></li><li class="footnote" id="fn-1"><p>I&apos;m asking Web Page Test to load my page using IE10. I get much faster load times using Chrome or Firefox locally which is what most of my readers use. This is good enough for now.<a href="#fnref1">↩</a></p></li><li class="footnote" id="fn-2"><p>I mean, the starting point was probably good enough but if I admitted that then I wouldn&apos;t have had the excuse to dig into my site&apos;s load time.<a href="#fnref2">↩</a></p></li></ol></div>]]></content>
  </entry>
</feed>
