<?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom"><link href="https://scurker.com"/><title>scurker.com</title><updated>2018-12-12T00:00:00+00:00</updated><id>https://scurker.com/</id><author><name>Jason Wilson</name></author><atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="https://scurker.com/feed"/><!-- feed entries --><entry><title>Primer to Measuring Page Speed</title><link href="https://scurker.com/primer-to-measuring-page-speed"/><id>https://scurker.com/primer-to-measuring-page-speed</id><updated>2018-12-12T00:00:00+00:00</updated><content type="html">&lt;p&gt;That are many different things that contribute to the speed of a page load. The amount of javascript that is being loading, the code that is being run in javascript, or even how assets are being loaded. Understanding the things that impact a page load can be overwhelming, but making small improvements can make a gradual impact towards making pages load faster.&lt;/p&gt; &lt;p&gt;But how do you know if your site is slow or fast?&lt;/p&gt; &lt;blockquote class&#x3D;&quot;twitter-tweet&quot; align&#x3D;&quot;center&quot; data-dnt&#x3D;&quot;true&quot;&gt;&lt;p lang&#x3D;&quot;en&quot; dir&#x3D;&quot;ltr&quot;&gt;Want to make faster websites?&lt;br&gt;&lt;br&gt;Measure it.&lt;br&gt;&lt;br&gt;We implemented something that is supposed to be faster &amp;#x2014; but it&amp;#x2019;s not, and we only knew because we measured it.&lt;/p&gt;&amp;#x2014; Jason (@scurker) &lt;a href&#x3D;&quot;https://twitter.com/scurker/status/1057719401292673024?ref_src&#x3D;twsrc%5Etfw&quot;&gt;October 31, 2018&lt;/a&gt;&lt;/blockquote&gt; &lt;p&gt;Measuring is a key component of helping to make sites faster. Without having some baseline measurements to compare changes against, or knowing what performance targets you want to hit - it&amp;apos;s very difficult to actually know if the changes being made are having a positive effect.&lt;/p&gt; &lt;h2 id&#x3D;&quot;key-terms&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#key-terms&quot;&gt;&lt;/a&gt;Key Terms&lt;/h2&gt; &lt;p&gt;In order to first measure something, one must understand the different terms of measurement. A page load isn&amp;apos;t made up of a single specific metric as there are different aspects of loading that happen over a span of time. Understanding these measurements help point out specific areas to profile and improve.&lt;/p&gt; &lt;p&gt;However, what we particularly care about are the measurements that are directly related to how a user &lt;em&gt;perceives&lt;/em&gt; how fast a given page is.&lt;/p&gt; &lt;h3 id&#x3D;&quot;time-to-first-byte-ttfb&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#time-to-first-byte-ttfb&quot;&gt;&lt;/a&gt;Time to First Byte (TTFB)&lt;/h3&gt; &lt;p&gt;&lt;abbr title&#x3D;&quot;Time to first byte&quot;&gt;TTFB&lt;/abbr&gt; is a key metric for measuring server performance. This metric measures the time from the initial client request, to when the client receives its first byte. It&amp;apos;s important to note the user will never see content during this phase.&lt;/p&gt; &lt;h3 id&#x3D;&quot;first-contentful-paint-fcp&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#first-contentful-paint-fcp&quot;&gt;&lt;/a&gt;First Contentful Paint (FCP)&lt;/h3&gt; &lt;p&gt;After the initial request starts to return content, &lt;abbr title&#x3D;&quot;First contentful paint&quot;&gt;FCP&lt;/abbr&gt; helps to measure when the user first sees some &lt;em&gt;meaningful&lt;/em&gt; content, such as text or images. This is the first indication to the user that something is happening.&lt;/p&gt; &lt;h3 id&#x3D;&quot;first-meaningful-paint-fmp&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#first-meaningful-paint-fmp&quot;&gt;&lt;/a&gt;First Meaningful Paint (FMP)&lt;/h3&gt; &lt;p&gt;&lt;abbr title&#x3D;&quot;First meaningful paint&quot;&gt;FMP&lt;/abbr&gt; this is the first paint activity that is actually meaningful and contains content that is useful to the user. There&amp;apos;s no standard definition of when this happens, as the content that is meaningful to the user can very from page to page. In order to track &lt;abbr title&#x3D;&quot;First meaningful paint&quot;&gt;FMP&lt;/abbr&gt;, you will need to place specific user timings to track what you would consider to be the first meaningful paint to be, such as above the fold content or specific hero elements.&lt;/p&gt; &lt;h3 id&#x3D;&quot;time-to-interactive-tti&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#time-to-interactive-tti&quot;&gt;&lt;/a&gt;Time to Interactive (TTI)&lt;/h3&gt; &lt;p&gt;&lt;abbr title&#x3D;&quot;Time to interactive&quot;&gt;TTI&lt;/abbr&gt; happens after the first bit of content renders, and when the page responds to user interactions within 50ms. Long gaps between &lt;abbr title&#x3D;&quot;First contentful paint&quot;&gt;FCP&lt;/abbr&gt; or &lt;abbr title&#x3D;&quot;First meaningful paint&quot;&gt;FMP&lt;/abbr&gt; and &lt;abbr title&#x3D;&quot;Time to interactive&quot;&gt;TTI&lt;/abbr&gt; can lead to a bit of an &amp;quot;uncanny valley&amp;quot; experience for users, since a page may appear to be ready but user interactions are slow or unresponsive.&lt;/p&gt; &lt;h3 id&#x3D;&quot;dom-content-loaded&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#dom-content-loaded&quot;&gt;&lt;/a&gt;DOM Content Loaded&lt;/h3&gt; &lt;p&gt;&lt;code&gt;DOMContentLoaded&lt;/code&gt; is an event when the DOM is ready and there are no more stylesheets blocking javascript execution. This may not be a significant metric for users since it may not actually mirror the experience of when it appears to a user that a page is loaded.&lt;/p&gt; &lt;h3 id&#x3D;&quot;load&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#load&quot;&gt;&lt;/a&gt;Load&lt;/h3&gt; &lt;p&gt;Finally, the &lt;code&gt;load&lt;/code&gt; event that happens after everything on a page has completely loaded. However, a user may be able to interact and view meaningful content well before this event occurs.&lt;/p&gt; &lt;p&gt;Here&amp;apos;s a simplified visualization of what these events might look like on a timeline:&lt;/p&gt; &lt;img src&#x3D;&quot;/assets/images/posts/timeline-performance-metrics.svg&quot; alt&#x3D;&quot;timeline performance metrics&quot; width&#x3D;&quot;800&quot;&gt; &lt;p&gt;Of these events, the ones we care about are the ones that help answer how a user might perceive the given speed of a page:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;em&gt;Is something happening?&lt;/em&gt; - First Contentful Paint (&lt;abbr title&#x3D;&quot;First contentful paint&quot;&gt;FCP&lt;/abbr&gt;)&lt;/li&gt; &lt;li&gt;&lt;em&gt;Is it useful?&lt;/em&gt; - First Meaningful Paint (&lt;abbr title&#x3D;&quot;First meaningful paint&quot;&gt;FMP&lt;/abbr&gt;)&lt;/li&gt; &lt;li&gt;&lt;em&gt;Can it be used?&lt;/em&gt; - Time to Interactive (&lt;abbr title&#x3D;&quot;Time to interactive&quot;&gt;TTI&lt;/abbr&gt;)&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Now that we know a little bit more about some of the different page speed metrics, let&amp;apos;s take a look at some sample of tools that help to profile and provide insights into your page speed.&lt;/p&gt; &lt;h2 id&#x3D;&quot;lighthouse&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#lighthouse&quot;&gt;&lt;/a&gt;Lighthouse&lt;/h2&gt; &lt;p&gt;&lt;a href&#x3D;&quot;https://developers.google.com/web/tools/lighthouse/&quot;&gt;Lighthouse&lt;/a&gt; is built into Google Chrome&amp;apos;s developer tools along with being available as a &lt;a href&#x3D;&quot;https://github.com/GoogleChrome/lighthouse&quot;&gt;CLI or via a node module&lt;/a&gt;. Lighthouse is a great place to start to capture a quick overview of common performance metrics as well as scoring a lot of other useful things.&lt;/p&gt; &lt;p&gt;&lt;img src&#x3D;&quot;/assets/images/posts/lighthouse-audit-results.png&quot; alt&#x3D;&quot;scurker.com lighthouse audit results&quot;&gt;&lt;/p&gt; &lt;p&gt;Using Lighthouse directly from Chrome&amp;apos;s devtools is the easiest way to get started, and provides the 3 key metrics we&amp;apos;re looking for: &lt;abbr title&#x3D;&quot;First contentful paint&quot;&gt;FCP&lt;/abbr&gt;, &lt;abbr title&#x3D;&quot;First meaningful paint&quot;&gt;FMP&lt;/abbr&gt;, and &lt;abbr title&#x3D;&quot;Time to interactive&quot;&gt;TTI&lt;/abbr&gt;. From the report, you can view tips and suggestions on things to improve to help make your page faster along with viewing the trace to dig into the details.&lt;/p&gt; &lt;p&gt;Since you are likely running Lighthouse locally, the results can vary from what real users may experience. Results can be skewed by other Chrome extensions, background programs, or even network behavior. For the cleanest results it&amp;apos;s recommended to run Lighthouse in either an incognito window or in a separate Chrome profile without any Chrome extensions enabled.&lt;/p&gt; &lt;p&gt;As previously mentioned, Lighthouse is a great place to start - but may not accurate reflect what your real-world users are experiencing. Which brings us to our next tool...&lt;/p&gt; &lt;h2 id&#x3D;&quot;webpagetestorg&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#webpagetestorg&quot;&gt;&lt;/a&gt;Webpagetest.org&lt;/h2&gt; &lt;p&gt;&lt;a href&#x3D;&quot;https://www.webpagetest.org/&quot;&gt;Webpagetest.org&lt;/a&gt; is a great tool for measuring speed from real world locations with real user connection speeds on a variety of different browsers and devices.&lt;/p&gt; &lt;p&gt;&lt;img src&#x3D;&quot;/assets/images/posts/web-page-test.png&quot; alt&#x3D;&quot;web page test site&quot;&gt;&lt;/p&gt; &lt;p&gt;Since WebPageTest runs on real devices there&amp;apos;s a limited pool available so test times may vary depending on the number of people running tests.&lt;/p&gt; &lt;p&gt;Given the variety of options, it&amp;apos;s easy to configure the different options to get a ballpark metric of what real world users are seeing:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Connection Speed&lt;/li&gt; &lt;li&gt;Number of Tests to Run (more tests will provide an average of the results and be less susceptible to abnormal spikes)&lt;/li&gt; &lt;li&gt;Repeat or First View (comparing between initial (uncached) or repeat (cached) times)&lt;/li&gt; &lt;li&gt;Capture video (provide a film strip of the page load over time)&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;&lt;img src&#x3D;&quot;/assets/images/posts/web-page-test-results.png&quot; alt&#x3D;&quot;web page test scurker.com results&quot;&gt;&lt;/p&gt; &lt;p&gt;The output from WebPageTest provides a cornucopia of results and metrics, along with a resource of other items to review. The 2 of the 3 key metrics are provided as well, Start Render (&lt;abbr title&#x3D;&quot;First contentful paint&quot;&gt;FCP&lt;/abbr&gt;) and First Interactive (&lt;abbr title&#x3D;&quot;Time to interactive&quot;&gt;TTI&lt;/abbr&gt;). In the results you can review your page&amp;apos;s waterfall, which mirrors what you would see in Chrome&amp;apos;s dev tools.&lt;/p&gt; &lt;p&gt;For more advanced metrics (such as &lt;abbr title&#x3D;&quot;First meaningful paint&quot;&gt;FMP&lt;/abbr&gt;) there is a &lt;a href&#x3D;&quot;https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/scripting&quot;&gt;custom metrics option&lt;/a&gt; that allows you to run arbitrary javascript at the end of a test to collect custom metrics. From here you could retrieve a specific &lt;a href&#x3D;&quot;https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API&quot;&gt;user timing&lt;/a&gt; to be returned to the WebPageTest front-end.&lt;/p&gt; &lt;p&gt;There are limitations to the public version of WebPageTest, as you are sharing instances with other users but there is a &lt;a href&#x3D;&quot;https://github.com/WPO-Foundation/webpagetest-docs/blob/master/user/Private%20Instances/README.md&quot;&gt;self hosting option&lt;/a&gt; if you need more custimization or reliability.&lt;/p&gt; &lt;h2 id&#x3D;&quot;puppeteer&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#puppeteer&quot;&gt;&lt;/a&gt;Puppeteer&lt;/h2&gt; &lt;p&gt;&lt;a href&#x3D;&quot;https://github.com/GoogleChrome/puppeteer&quot;&gt;Puppeteer&lt;/a&gt; is a node library that provides a high-level API to control Chrome/Chromium and allows for the ultimate flexibility in capturing page speed metrics. While Puppeteer may not be as simple to use as the previous tools, it does offer an extended ability to track additional custom metrics.&lt;/p&gt; &lt;h3 id&#x3D;&quot;getting-started-with-puppeteer&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#getting-started-with-puppeteer&quot;&gt;&lt;/a&gt;Getting Started with Puppeteer&lt;/h3&gt; &lt;p&gt;To get started with Puppeteer, you either need to have it installed globally (&lt;code&gt;npm install -g puppeteer&lt;/code&gt;) or locally inside of a project (&lt;code&gt;npm install puppeteer&lt;/code&gt;).&lt;/p&gt; &lt;p&gt;With Puppeteer you have access to the &lt;a href&#x3D;&quot;https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-browser&quot;&gt;&lt;code&gt;browser&lt;/code&gt;&lt;/a&gt; to control the Chrome instance, and &lt;a href&#x3D;&quot;https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page&quot;&gt;&lt;code&gt;page&lt;/code&gt;&lt;/a&gt; allowing you to control various page aspects such as the viewport size, or navigation. Additionally creating a CDPSession is used to access the &lt;a href&#x3D;&quot;https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#targetcreatecdpsession&quot;&gt;Chrome Devtools Protocol&lt;/a&gt; for things that are not natively available through the Puppeteer api.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;These examples are heavily dependant upon &lt;a href&#x3D;&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function&quot;&gt;&lt;code&gt;async&lt;/code&gt;&lt;/a&gt; and &lt;a href&#x3D;&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await&quot;&gt;&lt;code&gt;await&lt;/code&gt;&lt;/a&gt; so for native Node support, you will need to be using Node 8 or greater.&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; puppeteer &#x3D; &lt;span class&#x3D;&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;puppeteer&amp;apos;&lt;/span&gt;); (&lt;span class&#x3D;&quot;keyword&quot;&gt;async&lt;/span&gt; &lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class&#x3D;&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{ &lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; browser &#x3D; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; puppeteer.launch(); &lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; page &#x3D; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; browser.newPage(); &lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; client &#x3D; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.target().createCDPSession(); &lt;span class&#x3D;&quot;comment&quot;&gt;// capture results&lt;/span&gt; })();&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;navigating-to-a-page&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#navigating-to-a-page&quot;&gt;&lt;/a&gt;Navigating to a Page&lt;/h3&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.goto(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;https://example.com&amp;apos;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt; &lt;span class&#x3D;&quot;demo-link&quot;&gt; &lt;a href&#x3D;&quot;https://github.com/scurker/page-speed-metrics-with-puppeteer/blob/master/examples/navigate-to-page.js&quot;&gt;view navigating to a page example&lt;/a&gt; &lt;/span&gt; &lt;p&gt;The above step works for pages where no authentication or user interaction is required. For more complex steps, Puppeteer allows for complete control of the page to perform any interactions that typically require a user.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.goto(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;https://example.com&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.type(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#username&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;username&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.type(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#password&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;password&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.$&lt;span class&#x3D;&quot;built_in&quot;&gt;eval&lt;/span&gt;(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#login&amp;apos;&lt;/span&gt;, form &#x3D;&amp;gt; form.submit()); &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.waitForNavigation();&lt;/code&gt;&lt;/pre&gt; &lt;span class&#x3D;&quot;demo-link&quot;&gt; &lt;a href&#x3D;&quot;https://github.com/scurker/page-speed-metrics-with-puppeteer/blob/master/examples/navigate-to-page-with-login.js&quot;&gt;view authentication example&lt;/a&gt; &lt;/span&gt; &lt;h3 id&#x3D;&quot;simulating-network-speed&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#simulating-network-speed&quot;&gt;&lt;/a&gt;Simulating Network Speed&lt;/h3&gt; &lt;p&gt;For more &amp;quot;real world&amp;quot; page speed metrics, we need to simulate slower network conditions. Puppeteer can emulate these conditions using the &lt;a href&#x3D;&quot;https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#targetcreatecdpsession&quot;&gt;Chrome Devtools Protocol&lt;/a&gt; and &lt;a href&#x3D;&quot;https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions&quot;&gt;&lt;code&gt;Network.emulateNetworkConditions&lt;/code&gt;&lt;/a&gt;. &lt;code&gt;Network.emulateNetworkConditions&lt;/code&gt; expects throughput in bits vs bytes, so you will need to divide any byte value by &lt;code&gt;8&lt;/code&gt; for accurate results.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;comment&quot;&gt;// Simulate 3G Conditions&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; client.send(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;Network.emulateNetworkConditions&amp;apos;&lt;/span&gt;, { &lt;span class&#x3D;&quot;attr&quot;&gt;offline&lt;/span&gt;: &lt;span class&#x3D;&quot;literal&quot;&gt;false&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;downloadThroughput&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;1.6&lt;/span&gt; * &lt;span class&#x3D;&quot;number&quot;&gt;1024&lt;/span&gt; * &lt;span class&#x3D;&quot;number&quot;&gt;1024&lt;/span&gt; / &lt;span class&#x3D;&quot;number&quot;&gt;8&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// 1.6 mb/s&lt;/span&gt; uploadThroughput: &lt;span class&#x3D;&quot;number&quot;&gt;768&lt;/span&gt; * &lt;span class&#x3D;&quot;number&quot;&gt;1024&lt;/span&gt; / &lt;span class&#x3D;&quot;number&quot;&gt;8&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// 400 kb/s&lt;/span&gt; latency: &lt;span class&#x3D;&quot;number&quot;&gt;300&lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;// 300ms&lt;/span&gt; });&lt;/code&gt;&lt;/pre&gt; &lt;span class&#x3D;&quot;demo-link&quot;&gt; &lt;a href&#x3D;&quot;https://github.com/scurker/page-speed-metrics-with-puppeteer/blob/master/examples/simulate-network-speed.js&quot;&gt;view simulate network speed example&lt;/a&gt; &lt;/span&gt; &lt;h3 id&#x3D;&quot;tracking-cached-vs-first-view&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#tracking-cached-vs-first-view&quot;&gt;&lt;/a&gt;Tracking Cached vs First View&lt;/h3&gt; &lt;p&gt;For measuring a first view request, there&amp;apos;s two things that need to happen: prevent requests from being fetched from the cache and preventing requests from being fetched via a service worker (if available). There&amp;apos;s no direct access (&lt;a href&#x3D;&quot;https://github.com/GoogleChrome/puppeteer/issues/2634&quot;&gt;yet&lt;/a&gt;) to shutting down a service worker, but service workers can be &lt;a href&#x3D;&quot;https://chromedevtools.github.io/devtools-protocol/tot/ServiceWorker#method-unregister&quot;&gt;unregistered&lt;/a&gt; using the Chrome Devtools Protocol. Service workers need to be unregistered &lt;em&gt;per page request&lt;/em&gt;, so the protocol will need to be called for each iteration.&lt;/p&gt; &lt;p&gt;Whether you want cached or first view speed metrics is dependant on the type of your application and how your users use it. For applications with heavy repeat usage, it&amp;apos;s likely knowing cached times will be a better measurement of real world usage.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; metrics &#x3D; []; &lt;span class&#x3D;&quot;comment&quot;&gt;// array for collecting metrics per iteration&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; runs &#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;10&lt;/span&gt;; &lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; useCache &#x3D; &lt;span class&#x3D;&quot;literal&quot;&gt;false&lt;/span&gt;; &lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; useServiceWorker &#x3D; &lt;span class&#x3D;&quot;literal&quot;&gt;false&lt;/span&gt;; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.setCacheEnabled(useCache); &lt;span class&#x3D;&quot;keyword&quot;&gt;async&lt;/span&gt; &lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class&#x3D;&quot;title&quot;&gt;disableServiceWorker&lt;/span&gt;(&lt;span class&#x3D;&quot;params&quot;&gt;disable&lt;/span&gt;) &lt;/span&gt;{ &lt;span class&#x3D;&quot;keyword&quot;&gt;if&lt;/span&gt;(disable) { &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; client.send(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;ServiceWorker.enable&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; client.send(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;ServiceWorker.unregister&amp;apos;&lt;/span&gt;, { &lt;span class&#x3D;&quot;attr&quot;&gt;scopeURL&lt;/span&gt;: &lt;span class&#x3D;&quot;keyword&quot;&gt;new&lt;/span&gt; URL(page.url()).origin }); } } &lt;span class&#x3D;&quot;keyword&quot;&gt;for&lt;/span&gt;(&lt;span class&#x3D;&quot;keyword&quot;&gt;let&lt;/span&gt; i &#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;; i &amp;lt; runs; i++) { &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; disableServiceWorker(!useServiceWorker); &lt;span class&#x3D;&quot;comment&quot;&gt;// capture metrics per iteration&lt;/span&gt; }&lt;/code&gt;&lt;/pre&gt; &lt;div class&#x3D;&quot;demo-link&quot;&gt; &lt;a href&#x3D;&quot;https://github.com/scurker/page-speed-metrics-with-puppeteer/blob/master/examples/disable-caching.js&quot;&gt;view disable cache example&lt;/a&gt; &lt;/div&gt; &lt;div class&#x3D;&quot;demo-link&quot;&gt; &lt;a href&#x3D;&quot;https://github.com/scurker/page-speed-metrics-with-puppeteer/blob/master/examples/disable-service-worker.js&quot;&gt;view disable service worker example&lt;/a&gt; &lt;/div&gt; &lt;h3 id&#x3D;&quot;tracking-page-metrics&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#tracking-page-metrics&quot;&gt;&lt;/a&gt;Tracking Page Metrics&lt;/h3&gt; &lt;p&gt;Page speed metrics need to be captured over multiple iterations to minimize any natural variations that might occur. We can collect these metrics using the &lt;a href&#x3D;&quot;https://developer.mozilla.org/en-US/docs/Web/API/Performance&quot;&gt;Performance API&lt;/a&gt;. This allows us to collect the native measurements we&amp;apos;re interesting in, such as navigation and paint as well as custom measurements.&lt;/p&gt; &lt;p&gt;To track custom measurements, you will need to create measurements with &lt;a href&#x3D;&quot;https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark&quot;&gt;&lt;code&gt;Performance.mark()&lt;/code&gt;&lt;/a&gt; or &lt;a href&#x3D;&quot;https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark&quot;&gt;&lt;code&gt;Performance.measure()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt; &lt;h4 id&#x3D;&quot;tracking-first-meaningful-paint&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#tracking-first-meaningful-paint&quot;&gt;&lt;/a&gt;Tracking First Meaningful Paint&lt;/h4&gt; &lt;p&gt;Since there is no standardized measurement for &lt;abbr title&#x3D;&quot;First meaningful paint&quot;&gt;FMP&lt;/abbr&gt;, you will need to manually include a performance mark to indicate where the first meaningful paint should happen.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&amp;lt;&lt;span class&#x3D;&quot;keyword&quot;&gt;div&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;class&lt;/span&gt;&#x3D;&lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;hero&amp;quot;&lt;/span&gt;&amp;gt; ... &amp;lt;/&lt;span class&#x3D;&quot;keyword&quot;&gt;div&lt;/span&gt;&amp;gt; &amp;lt;&lt;span class&#x3D;&quot;keyword&quot;&gt;script&lt;/span&gt;&amp;gt; performance.mark(&amp;apos;&lt;span class&#x3D;&quot;keyword&quot;&gt;first&lt;/span&gt;-meaningful-paint&amp;apos;); &amp;lt;/&lt;span class&#x3D;&quot;keyword&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id&#x3D;&quot;tracking-time-to-interactive&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#tracking-time-to-interactive&quot;&gt;&lt;/a&gt;Tracking Time to Interactive&lt;/h4&gt; &lt;p&gt;While puppeteer doesn&amp;apos;t provide &lt;abbr title&#x3D;&quot;Time to interactive&quot;&gt;TTI&lt;/abbr&gt;, there are other things that you can track that can still provide some indication of interactiveness. If you&amp;apos;re using a javascript library such as React or Vue, you could use lifecycle hooks inside of an important component to indicate that things are ready.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;React Example&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;class&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class&#x3D;&quot;title&quot;&gt;ImportantComponent&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;extends&lt;/span&gt; &lt;span class&#x3D;&quot;title&quot;&gt;React&lt;/span&gt;.&lt;span class&#x3D;&quot;title&quot;&gt;Component&lt;/span&gt; &lt;/span&gt;{ componentDidMount() { performance.mark(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;important component mounted&amp;apos;&lt;/span&gt;); } }&lt;/code&gt;&lt;/pre&gt; &lt;blockquote&gt; &lt;p&gt;Vue Example&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;export&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;default&lt;/span&gt; { mounted() { &lt;span class&#x3D;&quot;keyword&quot;&gt;this&lt;/span&gt;.$nextTick(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;()&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; performance.mark(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;important component mounted&amp;apos;&lt;/span&gt;)); } }&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Since these measurements will largely be app specific, there&amp;apos;s no standard way to set where these measurements should be placed.&lt;/p&gt; &lt;p&gt;With puppeteer, we can use &lt;a href&#x3D;&quot;https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageevaluatepagefunction-args&quot;&gt;&lt;code&gt;page.evaluate()&lt;/code&gt;&lt;/a&gt; to run a function inside the context of the page. This can be used to access the performance api and return the results to our script.&lt;/p&gt; &lt;p&gt;In addition, for each iteration we likely want to wait some time between requests to not introduce significant load to the server. Using &lt;code&gt;page.waitFor()&lt;/code&gt; between iterations will allow for some time to ease the load.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;for&lt;/span&gt;(&lt;span class&#x3D;&quot;keyword&quot;&gt;let&lt;/span&gt; i &#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;; i &amp;lt; runs; i++) { &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; disableServiceWorker(!useServiceWorker); &lt;span class&#x3D;&quot;comment&quot;&gt;// Allow time between requests&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.waitFor(&lt;span class&#x3D;&quot;number&quot;&gt;500&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.reload({ &lt;span class&#x3D;&quot;attr&quot;&gt;waitUntil&lt;/span&gt;: &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;networkIdle0&amp;apos;&lt;/span&gt; }); &lt;span class&#x3D;&quot;keyword&quot;&gt;let&lt;/span&gt; navigationMetrics &#x3D; &lt;span class&#x3D;&quot;built_in&quot;&gt;JSON&lt;/span&gt;.parse( &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.evaluate(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;()&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;JSON&lt;/span&gt;.stringify(performance.getEntriesByType(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;navigation&amp;apos;&lt;/span&gt;)) ) ); &lt;span class&#x3D;&quot;keyword&quot;&gt;let&lt;/span&gt; firstContentfulPaint &#x3D; &lt;span class&#x3D;&quot;built_in&quot;&gt;JSON&lt;/span&gt;.parse( &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.evaluate(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;()&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;JSON&lt;/span&gt;.stringify(performance.getEntriesByName(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;first-contentful-paint&amp;apos;&lt;/span&gt;)) ) ); &lt;span class&#x3D;&quot;keyword&quot;&gt;let&lt;/span&gt; firstMeaningfulPaint &#x3D; &lt;span class&#x3D;&quot;built_in&quot;&gt;JSON&lt;/span&gt;.parse( &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; page.evaluate(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;()&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;JSON&lt;/span&gt;.stringify(performance.getEntriesByName(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;first-meaningful-paint&amp;apos;&lt;/span&gt;)) ) ); &lt;span class&#x3D;&quot;comment&quot;&gt;// any other additional custom metrics can be included and tracked&lt;/span&gt; metrics.push({ &lt;span class&#x3D;&quot;attr&quot;&gt;responseEnd&lt;/span&gt;: navigationMetrics[&lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;].responseEnd, &lt;span class&#x3D;&quot;attr&quot;&gt;loaded&lt;/span&gt;: navigationMetrics[&lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;].domContentLoadedEventEnd, &lt;span class&#x3D;&quot;attr&quot;&gt;complete&lt;/span&gt;: navigationMetrics[&lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;].domComplete, &lt;span class&#x3D;&quot;attr&quot;&gt;firstContentfulPaint&lt;/span&gt;: firstContentfulPaint[&lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;].startTime, &lt;span class&#x3D;&quot;attr&quot;&gt;firstMeaningfulPaint&lt;/span&gt;: firstMeaningfulPaint[&lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;].startTime }); } &lt;span class&#x3D;&quot;comment&quot;&gt;// Do something with the results&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; browser.close();&lt;/code&gt;&lt;/pre&gt; &lt;span class&#x3D;&quot;demo-link&quot;&gt; &lt;a href&#x3D;&quot;https://github.com/scurker/page-speed-metrics-with-puppeteer/blob/master/examples/everything.js&quot;&gt;view full puppeteer example&lt;/a&gt; &lt;/span&gt; &lt;p&gt;Once you&amp;apos;ve collected all of the metric results that your heart desires, be sure to call &lt;code&gt;browser.close()&lt;/code&gt; to ensure you don&amp;apos;t keep your Puppeteer instance running.&lt;/p&gt; &lt;h3 id&#x3D;&quot;analyzing-puppeteers-results&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#analyzing-puppeteers-results&quot;&gt;&lt;/a&gt;Analyzing Puppeteer&amp;apos;s Results&lt;/h3&gt; &lt;p&gt;There&amp;apos;s a number of things you could do to analyze the results from Puppeteer:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Toggle service worker on/off to see impact on repeat requests&lt;/li&gt; &lt;li&gt;Add additional custom metrics to see more granular results&lt;/li&gt; &lt;li&gt;Test against multiple network profiles&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Since you have near complete control over Chrome using puppeteer&amp;apos;s api, there&amp;apos;s few limitations in what speed metrics you can track provided you have placed useful marks in places that matter.&lt;/p&gt; &lt;h2 id&#x3D;&quot;measure-measure-measure-and-measure-again&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#measure-measure-measure-and-measure-again&quot;&gt;&lt;/a&gt;Measure, Measure, Measure (and measure again)&lt;/h2&gt; &lt;p&gt;Knowing how fast or slow your site is important, and it&amp;apos;s impossible to know without continually measuring and monitoring changes. For users that use your site every day, they feel pain when things don&amp;apos;t appear to be responsive. The tools listed above are by no means an exhaustive list, but are just a starting point to begin having a better understanding of the different metrics that affect your users. From this, hopefully you will feel more empowered to start tracking and measuring leading to a better experience for all of your users.&lt;/p&gt;</content></entry><entry><title>Clearing a Path for Offline</title><link href="https://scurker.com/clearing-a-path-for-offline"/><id>https://scurker.com/clearing-a-path-for-offline</id><updated>2018-06-05T00:00:00+00:00</updated><content type="html">&lt;p&gt;I&amp;apos;ve long known the benefits of service workers, but had not made the push to implement one for my own site. With the recent &lt;a href&#x3D;&quot;https://webkit.org/blog/8090/workers-at-your-service/&quot;&gt;change in Safari&lt;/a&gt; finally taking service workers to task, it was time to hop aboard the service worker train myself. Now if you visit my site, select pages will be available with offline viewing.&lt;/p&gt; &lt;p&gt;As of &lt;a href&#x3D;&quot;https://caniuse.com/#feat&#x3D;serviceworkers&quot;&gt;June 2018&lt;/a&gt;, 83% of global users have some form of service worker support so there&amp;apos;s little reason not to have one especially as mobile connectivity becomes more pervasive. If you&amp;apos;ve made it this far and still don&amp;apos;t know what a service worker is, &lt;a href&#x3D;&quot;https://developers.google.com/web/fundamentals/primers/service-workers/&quot;&gt;Google has an excellent primer&lt;/a&gt; all about the inner workings of service workers.&lt;/p&gt; &lt;h2 id&#x3D;&quot;a-worker-to-build&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#a-worker-to-build&quot;&gt;&lt;/a&gt;A worker to build&lt;/h2&gt; &lt;p&gt;I build my blog on top of &lt;a href&#x3D;&quot;http://www.metalsmith.io/&quot;&gt;metalsmith&lt;/a&gt;, and there was a couple of key aspects I wanted to build into my service worker:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Increment cache version for each static site build&lt;/li&gt; &lt;li&gt;Have my service worker automatically include built static assets&lt;/li&gt; &lt;li&gt;Have my offline page list previously visited offline pages&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;I am not going to suggest the path that I took towards the end result is one that should be similarly followed, but wanted to outline the steps that led me there.&lt;/p&gt; &lt;h3 id&#x3D;&quot;versioning&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#versioning&quot;&gt;&lt;/a&gt;Versioning&lt;/h3&gt; &lt;p&gt;Whenever a service worker changes, a new version is downloaded and installed. To ensure that the browser&amp;apos;s cache is up to date we want the service worker to have a new version key to be able to clear out older requests.&lt;/p&gt; &lt;p&gt;My static site doesn&amp;apos;t change frequently, so having a cache version based on date seems relatively safe. Using &lt;a href&#x3D;&quot;https://www.npmjs.com/package/rollup&quot;&gt;rollup&lt;/a&gt; in combination with &lt;a href&#x3D;&quot;https://www.npmjs.com/package/rollup-plugin-replace&quot;&gt;rollup-plugin-replace&lt;/a&gt; I can replace &lt;code&gt;CACHE_VERSION&lt;/code&gt; with the current date&amp;apos;s version string.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;span class&#x3D;&quot;selector-tag&quot;&gt;replace&lt;/span&gt;({ &lt;span class&#x3D;&quot;attribute&quot;&gt;CACHE_VERSION&lt;/span&gt;: JSON.&lt;span class&#x3D;&quot;built_in&quot;&gt;stringify&lt;/span&gt;( new Date().&lt;span class&#x3D;&quot;built_in&quot;&gt;toISOString&lt;/span&gt;().&lt;span class&#x3D;&quot;built_in&quot;&gt;split&lt;/span&gt;(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;T&amp;apos;&lt;/span&gt;)[&lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;].&lt;span class&#x3D;&quot;built_in&quot;&gt;replace&lt;/span&gt;(/-/g, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;&amp;apos;&lt;/span&gt;) ) })&lt;/code&gt;&lt;/pre&gt;&lt;h3 id&#x3D;&quot;including-assets&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#including-assets&quot;&gt;&lt;/a&gt;Including Assets&lt;/h3&gt; &lt;p&gt;Similarly to versioning above, I utilize rollup to scan my assets folder to match static assets and replace &lt;code&gt;STATIC_ASSETS&lt;/code&gt; with the array of assets to pre-cache in the service worker on install.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;replace({ &lt;span class&#x3D;&quot;attr&quot;&gt;STATIC_ASSETS&lt;/span&gt;: &lt;span class&#x3D;&quot;built_in&quot;&gt;JSON&lt;/span&gt;.stringify([ ...glob.sync(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;assets/**/*&amp;apos;&lt;/span&gt;, { &lt;span class&#x3D;&quot;attr&quot;&gt;cwd&lt;/span&gt;: path.resolve(__dirname, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;build&amp;apos;&lt;/span&gt;), &lt;span class&#x3D;&quot;attr&quot;&gt;nodir&lt;/span&gt;: &lt;span class&#x3D;&quot;literal&quot;&gt;true&lt;/span&gt; }).map(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;file&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&#x60;/&lt;span class&#x3D;&quot;subst&quot;&gt;${file}&lt;/span&gt;&#x60;&lt;/span&gt;) ], &lt;span class&#x3D;&quot;literal&quot;&gt;null&lt;/span&gt;, &lt;span class&#x3D;&quot;number&quot;&gt;2&lt;/span&gt;) })&lt;/code&gt;&lt;/pre&gt;&lt;h3 id&#x3D;&quot;listing-offline-posts&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#listing-offline-posts&quot;&gt;&lt;/a&gt;Listing offline posts&lt;/h3&gt; &lt;p&gt;For listing offline posts, I&amp;apos;m utilizing &lt;a href&#x3D;&quot;https://www.npmjs.com/package/metalsmith#useplugin&quot;&gt;metalsmith middleware&lt;/a&gt; to generate &lt;a href&#x3D;&quot;https://scurker.com/pages.json&quot;&gt;json metadata&lt;/a&gt; about my site to pre-cache in my service worker to later compare cached requests against known pages. I could just list visited offline posts by their url, but by generating and pre-caching metadata about any particular page, I can include page titles and dates to list &lt;a href&#x3D;&quot;/offline&quot;&gt;/offline&lt;/a&gt;.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-js&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;const&lt;/span&gt; isOfflinePage &#x3D; &lt;span class&#x3D;&quot;built_in&quot;&gt;document&lt;/span&gt;.body.classList.contains(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;offline-page&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class&#x3D;&quot;built_in&quot;&gt;window&lt;/span&gt;.caches &amp;amp;&amp;amp; isOfflinePage) { caches.keys() .then(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;keys&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; { &lt;span class&#x3D;&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;Promise&lt;/span&gt;.all([ caches.open(targetCache).then(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;c&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; c.keys()), fetch(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;/pages.json&amp;apos;&lt;/span&gt;).then(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;res&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; res.json()) ]); }) .then(&lt;span class&#x3D;&quot;function&quot;&gt;(&lt;span class&#x3D;&quot;params&quot;&gt;[ requests, pages ]&lt;/span&gt;) &#x3D;&amp;gt;&lt;/span&gt; { &lt;span class&#x3D;&quot;comment&quot;&gt;// match the requests in the cache against known posts&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;let&lt;/span&gt; posts &#x3D; pages.filter(&lt;span class&#x3D;&quot;function&quot;&gt;(&lt;span class&#x3D;&quot;params&quot;&gt;{ type }&lt;/span&gt;) &#x3D;&amp;gt;&lt;/span&gt; type &#x3D;&#x3D;&#x3D; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;post&amp;apos;&lt;/span&gt;) , matchedPosts &#x3D; posts.filter( &lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;post&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; requests.find(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;params&quot;&gt;req&lt;/span&gt; &#x3D;&amp;gt;&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;new&lt;/span&gt; URL(req.url).pathname.indexOf(post.path) !&#x3D;&#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;-1&lt;/span&gt;) ); &lt;span class&#x3D;&quot;keyword&quot;&gt;let&lt;/span&gt; offlineContainer &#x3D; &lt;span class&#x3D;&quot;built_in&quot;&gt;document&lt;/span&gt;.querySelector(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;.offline-posts&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;if&lt;/span&gt;(matchedPosts.length) { &lt;span class&#x3D;&quot;comment&quot;&gt;// display offline posts on the page&lt;/span&gt; } &lt;span class&#x3D;&quot;keyword&quot;&gt;else&lt;/span&gt; { offlineContainer.remove(); } }); }&lt;/code&gt;&lt;/pre&gt; &lt;h2 id&#x3D;&quot;there-are-many-service-workers--this-one-is-mine&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#there-are-many-service-workers--this-one-is-mine&quot;&gt;&lt;/a&gt;There are many service workers &amp;#x2013; this one is mine&lt;/h2&gt; &lt;p&gt;Beyond the methods outline above, my service worker isn&amp;apos;t a particularly specialized affair. Following patterns from &lt;a href&#x3D;&quot;https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook&quot;&gt;Jake Archibald&amp;apos;s offline cookbook&lt;/a&gt;, &lt;a href&#x3D;&quot;https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#on-install-not&quot;&gt;pre-caches assets on install&lt;/a&gt;, &lt;a href&#x3D;&quot;https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#on-activate&quot;&gt;removes old caches on activate&lt;/a&gt;, and serving content with a &lt;a href&#x3D;&quot;https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-falling-back-to-cache&quot;&gt;network first with cache fallback&lt;/a&gt; pattern.&lt;/p&gt; &lt;p&gt;For a full picture, you can view my service worker scripts below.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://github.com/scurker/scurker.com/blob/master/site/sw.js&quot;&gt;&lt;code&gt;sw.js&lt;/code&gt;&lt;/a&gt; &lt;em&gt;prebuild&lt;/em&gt;&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://scurker.com/sw.js&quot;&gt;&lt;code&gt;sw.js&lt;/code&gt;&lt;/a&gt; &lt;em&gt;postbuild&lt;/em&gt;&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://github.com/scurker/scurker.com/blob/master/rollup.sw.config.js&quot;&gt;&lt;code&gt;rollup.sw.config.js&lt;/code&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;h2 id&#x3D;&quot;thoughts-to-improve&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#thoughts-to-improve&quot;&gt;&lt;/a&gt;Thoughts to improve&lt;/h2&gt; &lt;p&gt;These are only my first steps towards a path for offline, but there are certain areas of improvement I could see. Service worker asset responses could follow a &lt;a href&#x3D;&quot;https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network&quot;&gt;cache with network fallback&lt;/a&gt; recipe since my assets aren&amp;apos;t likely to change frequently. Or, if I was to uniquely identify assets with some sort of asset hash could place assets into a more permanent cache only expiring assets if a new version is received.&lt;/p&gt;</content></entry><entry><title>Interesting talks at JSConf 2015</title><link href="https://scurker.com/interesting-talks-at-jsconf-2015"/><id>https://scurker.com/interesting-talks-at-jsconf-2015</id><updated>2015-05-31T00:00:00+00:00</updated><content type="html">&lt;p&gt;This is my second year of being able to attend JSConf and feel fortunate to be able to listen and interact with so many awesome people in the community. This is mostly a brain dump of some of the topics I found interesting at JSConf, but obviously isn&amp;apos;t every talk or speaker since I couldn&amp;apos;t attend every session. Hopefully, some others can benefit from some of the knowledge I gained - or find some interesting people to follow in the community.&lt;/p&gt; &lt;h2 id&#x3D;&quot;js-accessibility-and-js-side-by-side---felipe-de-albuquerque&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#js-accessibility-and-js-side-by-side---felipe-de-albuquerque&quot;&gt;&lt;/a&gt;JS Accessibility and JS: side-by-side - &lt;a href&#x3D;&quot;https://twitter.com/felipedeolinda&quot;&gt;Felipe de Albuquerque&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;This was an interesting talk on accessibility because the talk itself wasn&amp;apos;t presented in English. Felipe gave a few examples of why accessibility is important:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;650 million people have some some kind of disability&lt;/li&gt; &lt;li&gt;Kids can control websites through voice before they can read, so having voice control would allow young kids to navigate&lt;/li&gt; &lt;li&gt;The internet should be inclusive of everyone&lt;/li&gt; &lt;li&gt;Based on research, &lt;a href&#x3D;&quot;http://www.freedomscientific.com/Products/Blindness/JAWS&quot;&gt;JAWS&lt;/a&gt; is one of the most popular screen readers&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;One of the biggest issues we have in the community is the lack of developer knowledge with WAI-ARIA attributes. ARIA attributes are something that are ready to be implemented &lt;em&gt;today&lt;/em&gt;, and as a community we should be concerned about making our applications accessible to everyone.&lt;/p&gt; &lt;h2 id&#x3D;&quot;communicate-all-the-things---kyle-tyacke&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#communicate-all-the-things---kyle-tyacke&quot;&gt;&lt;/a&gt;Communicate All the Things - &lt;a href&#x3D;&quot;https://twitter.com/geekgonenomad&quot;&gt;Kyle Tyacke&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Building the web with WebRTC. If you&amp;apos;ve ever used Amazon Mayday, or Google Hangouts you&amp;apos;ve used WebRTC. WebRTC is similar to web sockets, but uses peer-to-peer connections instead of communicating with a server.&lt;/p&gt; &lt;p&gt;&lt;a href&#x3D;&quot;https://github.com/respoke/apollo&quot;&gt;Apollo&lt;/a&gt; is a JavaScript library built on &lt;a href&#x3D;&quot;https://www.respoke.io/&quot;&gt;respoke&lt;/a&gt; that helps to handle those peer-to-peer connections. From there you can create peer-to-peer chat or video connections directly in your application.&lt;/p&gt; &lt;h2 id&#x3D;&quot;async-programing-in-es7-es2016---jafar-husain&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#async-programing-in-es7-es2016---jafar-husain&quot;&gt;&lt;/a&gt;Async Programing in &lt;del&gt;ES7&lt;/del&gt; ES2016 - &lt;a href&#x3D;&quot;http://twitter.com/Jhusain&quot;&gt;Jafar Husain&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;How do we make async easier? What if you could write async programs without any callbacks at all? What if waiting was just as easy as creating blocking functions?&lt;/p&gt; &lt;p&gt;With ES2016, you can use generators to write blocking or asynchronous code exactly the same:&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;async&lt;/span&gt; &lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class&#x3D;&quot;title&quot;&gt;foo&lt;/span&gt;(&lt;span class&#x3D;&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{ &lt;span class&#x3D;&quot;keyword&quot;&gt;var&lt;/span&gt; bar &#x3D; &lt;span class&#x3D;&quot;keyword&quot;&gt;await&lt;/span&gt; foobar(); &lt;span class&#x3D;&quot;keyword&quot;&gt;return&lt;/span&gt; bar; }&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Currently ES2016 is in the draft stage, but it&amp;apos;s expected to be part of the standard.&lt;/p&gt; &lt;p&gt;This was a great talk that helped explain some of the features &lt;del&gt;ES5&lt;/del&gt;ES2015 on generators and how they differ from iterators. One great point is that iterators are used for one-way functional communication, while generators are used for two-way functional communication. By calling &lt;code&gt;result.next(&amp;quot;value&amp;quot;)&lt;/code&gt; on a generator, you can push values to a generator function.&lt;/p&gt; &lt;p&gt;It&amp;apos;s hard to explain everything in short, but Jafar has created a repository that goes into further detail on &lt;a href&#x3D;&quot;https://github.com/jhusain/asyncgenerator&quot;&gt;generators, observables, and async generators&lt;/a&gt;.&lt;/p&gt; &lt;h2 id&#x3D;&quot;knitting-for-javascript---mariko-kosaka&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#knitting-for-javascript---mariko-kosaka&quot;&gt;&lt;/a&gt;Knitting for JavaScript - &lt;a href&#x3D;&quot;https://twitter.com/kosamari&quot;&gt;Mariko Kosaka&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Apparently there&amp;apos;s a &amp;quot;Github&amp;quot; for knitters, &lt;a href&#x3D;&quot;https://www.ravelry.com&quot;&gt;Ravelry&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Code for knitting.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;span class&#x3D;&quot;built_in&quot;&gt;R0&lt;/span&gt; : &lt;span class&#x3D;&quot;built_in&quot;&gt;k5&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;R1&lt;/span&gt;-&lt;span class&#x3D;&quot;number&quot;&gt;3&lt;/span&gt; : &lt;span class&#x3D;&quot;built_in&quot;&gt;k2&lt;/span&gt;, m1, k until &lt;span class&#x3D;&quot;number&quot;&gt;2&lt;/span&gt; sts remain, m1, &lt;span class&#x3D;&quot;built_in&quot;&gt;k2&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;R4&lt;/span&gt; : &lt;span class&#x3D;&quot;built_in&quot;&gt;k2&lt;/span&gt;, m1, &lt;span class&#x3D;&quot;built_in&quot;&gt;k1&lt;/span&gt;, m1, k until &lt;span class&#x3D;&quot;number&quot;&gt;3&lt;/span&gt; sts remain, m1, &lt;span class&#x3D;&quot;built_in&quot;&gt;k1&lt;/span&gt;, m1, &lt;span class&#x3D;&quot;built_in&quot;&gt;k2&lt;/span&gt; Repeat &lt;span class&#x3D;&quot;built_in&quot;&gt;R1&lt;/span&gt;-&lt;span class&#x3D;&quot;number&quot;&gt;4&lt;/span&gt; for &lt;span class&#x3D;&quot;number&quot;&gt;10&lt;/span&gt; &lt;span class&#x3D;&quot;built_in&quot;&gt;times&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That looks like something that could easily be created in javascript.&lt;/p&gt; &lt;p&gt;Mariko took two seemingly unrelated topics and merged them together to create something amazing and fascinating. This was a great talk that helped expose how JavaScript could be used for things that no one would really expect.&lt;/p&gt; &lt;p&gt;Kariko plans on putting up some of her code on Github at &lt;a href&#x3D;&quot;https://github.com/kosamari/electroknit&quot;&gt;electroknit&lt;/a&gt; and &lt;a href&#x3D;&quot;https://github.com/kosamari/color-mixer&quot;&gt;color-mixer&lt;/a&gt;.&lt;/p&gt; &lt;h2 id&#x3D;&quot;30-minutes-or-less-the-magic-of-automated-accessibility-testing---marcy-sutton&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#30-minutes-or-less-the-magic-of-automated-accessibility-testing---marcy-sutton&quot;&gt;&lt;/a&gt;30 Minutes or Less: The Magic of Automated Accessibility Testing - &lt;a href&#x3D;&quot;https://twitter.com/marcysutton&quot;&gt;Marcy Sutton&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;What are some the the accessibility basics you should be aware of?&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Alternative text&lt;/li&gt; &lt;li&gt;Document structure &amp;amp; hierarchy&lt;/li&gt; &lt;li&gt;HTML Semantics&lt;/li&gt; &lt;li&gt;Keyboard interactivity&lt;/li&gt; &lt;li&gt;Color contrast&lt;/li&gt; &lt;li&gt;Focus management&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Let the tooling do the heavy lifting for you! Tools can help you identify some of your accessibility issues.&lt;/p&gt; &lt;p&gt;In Chrome Canary, you can enable &lt;a href&#x3D;&quot;https://github.com/GoogleChrome/accessibility-developer-tools&quot;&gt;accessibility developer tools&lt;/a&gt; that will allow you to run audits on your page to help find those issues.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://www.npmjs.com/package/a11y&quot;&gt;A11Y (Ally)&lt;/a&gt; - run accessibility audits against a site.&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;http://marcysutton.com/angular-protractor-accessibility-plugin/&quot;&gt;Protractor + Accessibility Plugin&lt;/a&gt; - end to end testing accessibility plugin Angular JS&lt;/li&gt; &lt;/ul&gt;</content></entry><entry><title>In Harmony with Javascript - ES6, Javascript, and You</title><link href="https://scurker.com/in-harmony-with-javascript-es6-javascript-and-you"/><id>https://scurker.com/in-harmony-with-javascript-es6-javascript-and-you</id><updated>2015-04-25T00:00:00+00:00</updated><content type="html">&lt;p&gt;I have been wanting to give a talk on some of the exciting features of ES6 Harmony - and how you could start utilizing certain components of ES6 today, and &lt;a href&#x3D;&quot;http://www.barcampbham.com/&quot;&gt;BarCamp Birmingham&lt;/a&gt; was a great venue to introduce this talk.&lt;/p&gt; &lt;p&gt;It&amp;apos;s hard to talk about &lt;a href&#x3D;&quot;https://github.com/lukehoban/es6features&quot;&gt;all the great features&lt;/a&gt; that are a part of ES6, but I mainly wanted to touch on the ones that are usable today and the various strategies for implementing ES6 features as part of your code.&lt;/p&gt; &lt;p&gt;Want to know the short of it? For browsers, it&amp;apos;s fairly safe to use many of the ES6 features outlined below with the right polyfill. For node or io, io has better support out of the box while node 0.11.x+ requires specific ES6 feature flags enabled.&lt;/p&gt; &lt;div class&#x3D;&quot;video-wrapper&quot;&gt; &lt;iframe src&#x3D;&quot;//slides.com/scurker/es6-javascript-and-you/embed?style&#x3D;light&quot; width&#x3D;&quot;576&quot; height&#x3D;&quot;420&quot; scrolling&#x3D;&quot;no&quot; frameborder&#x3D;&quot;0&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;/iframe&gt; &lt;/div&gt; &lt;p&gt;Important links&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://github.com/lukehoban/es6features&quot;&gt;ES6 Complete Feature Set&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://status.modern.ie/?term&#x3D;es6&quot;&gt;Internet Explorer ES6 Support&lt;/a&gt; on modern.ie&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://kangax.github.io/compat-table/es6/&quot;&gt;ES6 Compatibility Tables&lt;/a&gt; including browsers and javascript engines&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://github.com/zloirock/core-js&quot;&gt;core-js&lt;/a&gt;, various polyfills for ES5, ES6, and ES7&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://github.com/paulmillr/es6-shim/&quot;&gt;es6-shim&lt;/a&gt; compatibility shims for ES6&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://babeljs.io/&quot;&gt;Babel&lt;/a&gt; a transpiler for compiling ES6 code to ES5&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://github.com/google/traceur-compiler&quot;&gt;Traceur&lt;/a&gt; compiles ES6 as well as some ES.next features&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;You can view the &lt;a href&#x3D;&quot;http://slides.com/scurker/es6-javascript-and-you&quot;&gt;full sets of slides over at slides.com&lt;/a&gt;.&lt;/p&gt;</content></entry><entry><title>Automated Deploys with Travis CI</title><link href="https://scurker.com/automated-deploys-with-travis-ci"/><id>https://scurker.com/automated-deploys-with-travis-ci</id><updated>2015-03-09T00:00:00+00:00</updated><content type="html">&lt;p&gt;If you read my previous post about &lt;a href&#x3D;&quot;/remote-deployments-with-git&quot;&gt;remote deployments with git&lt;/a&gt;, you should have a good idea on how you can deploy with a simple git push. This method works fine if you only work from one computer but starts to be a little more difficult if you want to use other devices (such as an tablet or phone) and potentially want to write posts or content directly on Github.&lt;/p&gt; &lt;h2 id&#x3D;&quot;bring-in-travis-ci&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#bring-in-travis-ci&quot;&gt;&lt;/a&gt;Bring in Travis CI&lt;/h2&gt; &lt;p&gt;If you aren&amp;apos;t using a CI (continuous integration) tool as part of your workflow, you should be! I&amp;apos;ve started to become a big fan of &lt;a href&#x3D;&quot;https://travis-ci.org&quot;&gt;Travis CI&lt;/a&gt; because it&amp;apos;s easy to setup, integrates easily with GitHub, and runs on a &lt;a href&#x3D;&quot;http://docs.travis-ci.com/user/getting-started/#Travis-CI-Overview&quot;&gt;number of different languages&lt;/a&gt;. And best of all, it&amp;apos;s free&lt;sup&gt;*&lt;/sup&gt;!&lt;/p&gt; &lt;p&gt;&lt;small&gt;* for open source projects&lt;/small&gt;&lt;/p&gt; &lt;p&gt;I use Travis to centralize my pushes so that I no longer have to have setup remote pushes from my local computer directly to my remote server to update content, but rather push directly to a Github branch and let Travis take care of the rest.&lt;/p&gt; &lt;h2 id&#x3D;&quot;getting-started&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#getting-started&quot;&gt;&lt;/a&gt;Getting Started&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;Remote server for hosting your site&lt;/li&gt; &lt;li&gt;Create limited access git user (recommended)&lt;/li&gt; &lt;li&gt;Create public/private SSH key pairs for authentication&lt;/li&gt; &lt;li&gt;Add public key to authorized SSH keys&lt;/li&gt; &lt;li&gt;Add private key to repository&lt;/li&gt; &lt;li&gt;Setup Travis&lt;/li&gt; &lt;li&gt;Setup travis.yml&lt;/li&gt; &lt;/ul&gt; &lt;h2 id&#x3D;&quot;generate-ssh-key-pairs&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#generate-ssh-key-pairs&quot;&gt;&lt;/a&gt;Generate SSH key pairs&lt;/h2&gt; &lt;p&gt;Since I don&amp;apos;t exactly feel comfortable giving Travis or Github my personal credentials to my own server, I&amp;apos;m using SSH authentication in order to grant access to push. In addition, I&amp;apos;ve created a &lt;a href&#x3D;&quot;http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server&quot;&gt;limited access git user&lt;/a&gt; that only has access to my git and web directories -- nothing else.&lt;/p&gt; &lt;p&gt;I&amp;apos;m not going to go into great detail on how to create your SSH key pairs, since Github has &lt;a href&#x3D;&quot;https://help.github.com/articles/generating-ssh-keys/&quot;&gt;already done that for us&lt;/a&gt;. You will need to login as your git user on your remote server, and generate a key pair following the above steps.&lt;/p&gt; &lt;p&gt;Once you&amp;apos;ve followed those steps, you should have two files &lt;code&gt;~/.ssh/id_rsa&lt;/code&gt;, your private key and &lt;code&gt;~/.ssh/id_rsa.pub&lt;/code&gt;, your public key. In order for the SSH authentication to work properly you will need to copy your public key into an authorized keys file.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;cat ~/.ssh/id_rsa.pub &amp;gt;&amp;gt; ~/.ssh/authorized_keys&lt;/code&gt;&lt;/pre&gt; &lt;h2 id&#x3D;&quot;add-private-key-to-repository&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#add-private-key-to-repository&quot;&gt;&lt;/a&gt;Add Private Key to Repository&lt;/h2&gt; &lt;p&gt;Now that you&amp;apos;ve created a SSH key pair, you will need to copy your private key so that Travis can use it to authenticate to your remote server. Since we don&amp;apos;t want to be putting our &lt;a href&#x3D;&quot;http://www.devfactor.net/2014/12/30/2375-amazon-mistake/&quot;&gt;private key unencrypted&lt;/a&gt; into Github, we&amp;apos;ll be using Travis to encrypt the key before we push it out for everyone to see. You will need to install either the Travis ruby gem, or travis-encrypt from npm if you haven&amp;apos;t already done so.&lt;/p&gt; &lt;h3 id&#x3D;&quot;ruby&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#ruby&quot;&gt;&lt;/a&gt;Ruby&lt;/h3&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-ruby&quot;&gt;gem install travis&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;npm&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#npm&quot;&gt;&lt;/a&gt;NPM&lt;/h3&gt; &lt;pre&gt;&lt;code&gt;npm &lt;span class&#x3D;&quot;keyword&quot;&gt;install&lt;/span&gt; travis-&lt;span class&#x3D;&quot;keyword&quot;&gt;encrypt&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I&amp;apos;m personally using the official Travis ruby gem, but the rest of the arguments should be about the same for both. You can read more about &lt;a href&#x3D;&quot;http://docs.travis-ci.com/user/encryption-keys/&quot;&gt;Travis encryption&lt;/a&gt;, but I&amp;apos;m going to give you the Cliff Notes&amp;#x2122; version here.&lt;/p&gt; &lt;p&gt;Assuming you&amp;apos;re already in your project directory, it&amp;apos;s as easy as...&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;mv id_rsa deploy_key touch .travis.yml &amp;amp;&amp;amp; travis encrypt-file deploy_key --add&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;This initializes the &lt;code&gt;.travis.yml&lt;/code&gt; file, encrypts your deploy key, and adds all the necessary information for Travis to be able to use that encrypted file.&lt;/p&gt; &lt;p&gt;You&amp;apos;ll need to commit your changes to Github, but before you do so remember to remove your private key &lt;code&gt;deploy_key&lt;/code&gt; and store it somewhere safe!&lt;/p&gt; &lt;h2 id&#x3D;&quot;setup-travis&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#setup-travis&quot;&gt;&lt;/a&gt;Setup Travis&lt;/h2&gt; &lt;p&gt;From here, you&amp;apos;ll want to to go to &lt;a href&#x3D;&quot;https://travis-ci.org/&quot;&gt;travis-ci.org&lt;/a&gt;, authenticate with Github, and turn on Travis for the repository that you wish to start deploying.&lt;/p&gt; &lt;p&gt;From here, you&amp;apos;ll need to make a few additions to your &lt;code&gt;.travis.yml&lt;/code&gt; file, and I&amp;apos;ll include an example, but you can of course always view the &lt;a href&#x3D;&quot;https://github.com/scurker/scurker.com/blob/master/.travis.yml&quot;&gt;latest version&lt;/a&gt; on Github.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-yaml&quot;&gt;&lt;span class&#x3D;&quot;attr&quot;&gt;language:&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;node_js&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;node_js:&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;0.10&amp;apos;&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;install:&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;echo&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;skip install&amp;quot;&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;branches:&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt; only:&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;master&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;after_success:&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;chmod&lt;/span&gt; &lt;span class&#x3D;&quot;number&quot;&gt;600&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy-key&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;mv&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy-key&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;~/.ssh/id_rsa&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;git&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;remote&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;add&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;ssh://git@example.com/var/git/site.git&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;git&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;push&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;before_install:&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;echo&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-e&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;Host example.com\n\tStrictHostKeyChecking no\n&amp;quot;&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;~/.ssh/config&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;openssl&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;aes-256-cbc&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-K&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;$encrypted_6a5cf90fd664_key&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-iv&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;$encrypted_6a5cf90fd664_iv&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt; -&lt;/span&gt;&lt;span class&#x3D;&quot;string&quot;&gt;in&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy-key.enc&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-out&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy-key&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-d&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;You&amp;apos;ll need to change things accordingly to your needs, but here&amp;apos;s a couple of tips:&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-yaml&quot;&gt;&lt;span class&#x3D;&quot;attr&quot;&gt;install:&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;echo&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;skip install&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;I&amp;apos;m essentially skipping this step because I&amp;apos;m only using Travis to deploy, but theoretically, you could use this to run tests before the deployment actually runs.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-yaml&quot;&gt;&lt;span class&#x3D;&quot;attr&quot;&gt;after_success:&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;chmod&lt;/span&gt; &lt;span class&#x3D;&quot;number&quot;&gt;600&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy-key&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;mv&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy-key&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;~/.ssh/id_rsa&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;git&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;remote&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;add&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;ssh://git@example.com/var/git/site.git&lt;/span&gt; &lt;span class&#x3D;&quot;bullet&quot;&gt;-&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;git&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;push&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;deploy&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Here&amp;apos;s where the bulk of the work actually happen. Your private key is copied to the appropriate directory, and the remote origin is created and pushed to.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;before_install: -&lt;span class&#x3D;&quot;ruby&quot;&gt; echo -e &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;Host example.com\n\tStrictHostKeyChecking no\n&amp;quot;&lt;/span&gt; &lt;span class&#x3D;&quot;meta&quot;&gt;&amp;gt;&amp;gt; &lt;/span&gt;~&lt;span class&#x3D;&quot;regexp&quot;&gt;/.ssh/config&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You will also need to change this to your domain as well, otherwise Travis may not be able to authenticate the domain and will sit there until the job times out.&lt;/p&gt; &lt;p&gt;With this, any time I push to Github Travis is able to deploy those changes and immediately push them out to this blog. You can always view &lt;a href&#x3D;&quot;https://github.com/scurker/scurker.com&quot;&gt;everything on Github&lt;/a&gt;.&lt;/p&gt;</content></entry><entry><title>Remote Deployments with Git</title><link href="https://scurker.com/remote-deployments-with-git"/><id>https://scurker.com/remote-deployments-with-git</id><updated>2015-01-25T00:00:00+00:00</updated><content type="html">&lt;p&gt;I&amp;apos;ve been deploying using git for my static and node sites for several months and wanted to offer some tips on how you can do the same. This is very similar to &lt;a href&#x3D;&quot;https://devcenter.heroku.com/articles/git&quot;&gt;heroku&amp;apos;s deployment model&lt;/a&gt; but using your own server in place of theirs.&lt;/p&gt; &lt;h3 id&#x3D;&quot;getting-started&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#getting-started&quot;&gt;&lt;/a&gt;Getting Started&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;Remote server for hosting your site&lt;/li&gt; &lt;li&gt;SSH access on remote server&lt;/li&gt; &lt;li&gt;Git installed locally and remotely&lt;/li&gt; &lt;li&gt;(optional) npm installed remotely&lt;/li&gt; &lt;li&gt;(optional) grunt installed remotely&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;For the remote server, you&amp;apos;ll need two different directories to store your files. One is where your site will be hosted, the other will be used for the git repository. I&amp;apos;m using &lt;code&gt;/var/www&lt;/code&gt; and &lt;code&gt;/var/git&lt;/code&gt; respectively, but you can choose differently based on your setup.&lt;/p&gt; &lt;h3 id&#x3D;&quot;create-remote-repository&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#create-remote-repository&quot;&gt;&lt;/a&gt;Create remote repository&lt;/h3&gt; &lt;p&gt;For the remote server, you&amp;apos;ll need to start with a bare git repository. This is where you will push your content to from your local machine.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;&lt;span class&#x3D;&quot;built_in&quot;&gt;cd&lt;/span&gt; /var/git mkdir site.git &amp;amp;&amp;amp; &lt;span class&#x3D;&quot;built_in&quot;&gt;cd&lt;/span&gt; site.git git init --bare&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;remote-dependencies&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#remote-dependencies&quot;&gt;&lt;/a&gt;Remote dependencies&lt;/h3&gt; &lt;p&gt;Whatever you&amp;apos;re using to build locally, you&amp;apos;ll also need to be sure those dependencies are installed on your remote server. I&amp;apos;m using &lt;a href&#x3D;&quot;https://www.npmjs.com/&quot;&gt;npm&lt;/a&gt; and &lt;a href&#x3D;&quot;http://gruntjs.com/&quot;&gt;grunt&lt;/a&gt; to build everything - but this could be ruby, jekyll or anything used to compile your site.&lt;/p&gt; &lt;p&gt;Since I&amp;apos;m using grunt, we&amp;apos;ll need to be sure that grunt-cli is installed globally.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;npm install -g grunt-cli&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;create-post-receive-hook&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#create-post-receive-hook&quot;&gt;&lt;/a&gt;Create post receive hook&lt;/h3&gt; &lt;p&gt;We&amp;apos;ll be using a &lt;a href&#x3D;&quot;http://git-scm.com/docs/githooks#post-receive&quot;&gt;post receive hook&lt;/a&gt; to run tasks after commits are received, such as building the site. Since your git directory probably isn&amp;apos;t where you&amp;apos;re serving up your files, you can use &lt;code&gt;--work-tree&lt;/code&gt; to set the working directory for your committed files.&lt;/p&gt; &lt;h4 id&#x3D;&quot;post-receive-hook&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#post-receive-hook&quot;&gt;&lt;/a&gt;post-receive hook&lt;/h4&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;&lt;span class&#x3D;&quot;meta&quot;&gt;#!/bin/sh &lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;# Use a build path as a temp staging directory before copying over&lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;# to the &amp;quot;live&amp;quot; web directory&lt;/span&gt; BUILD_PATH&#x3D;$(&lt;span class&#x3D;&quot;built_in&quot;&gt;cd&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;&lt;span class&#x3D;&quot;variable&quot;&gt;$(dirname &amp;quot;$0&amp;quot;)&lt;/span&gt;/..&amp;quot;&lt;/span&gt;; &lt;span class&#x3D;&quot;built_in&quot;&gt;pwd&lt;/span&gt;)/build WEB_PATH&#x3D;/var/www/example.com &lt;span class&#x3D;&quot;comment&quot;&gt;# Checkout latest version of files and cleanup untracked files&lt;/span&gt; git --work-tree&#x3D;&lt;span class&#x3D;&quot;variable&quot;&gt;$BUILD_PATH&lt;/span&gt; checkout -f git --work-tree&#x3D;&lt;span class&#x3D;&quot;variable&quot;&gt;$BUILD_PATH&lt;/span&gt; clean -fd &lt;span class&#x3D;&quot;built_in&quot;&gt;cd&lt;/span&gt; &lt;span class&#x3D;&quot;variable&quot;&gt;$BUILD_PATH&lt;/span&gt;; npm install --production &lt;span class&#x3D;&quot;comment&quot;&gt;# Use grunt to run a build task, but this could be anything you&lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;# want to use to generate your static site and/or run your node project&lt;/span&gt; grunt build &lt;span class&#x3D;&quot;comment&quot;&gt;# Clean web directory and copy static files to web directory&lt;/span&gt; (&lt;span class&#x3D;&quot;built_in&quot;&gt;cd&lt;/span&gt; &lt;span class&#x3D;&quot;variable&quot;&gt;$WEB_PATH&lt;/span&gt;;rm -rf *) (cp -r &lt;span class&#x3D;&quot;variable&quot;&gt;$BUILD_PATH&lt;/span&gt;/build/. &lt;span class&#x3D;&quot;variable&quot;&gt;$WEB_PATH&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Be sure you make the post-receive hook executable.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;chmod +x hooks/post-receive&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;set-up-push-to-deploy&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#set-up-push-to-deploy&quot;&gt;&lt;/a&gt;Set up Push to Deploy&lt;/h3&gt; &lt;p&gt;Now that everything is configured remotely, you&amp;apos;ll need to set up your local git to push to your remote server.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;git remote add deploy ssh://user@example.com/var/git/site.git&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Now, you can push files to your remote server with one simple command:&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;... git add . git commit -m &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;Updating files&amp;quot;&lt;/span&gt; git push deploy&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;If everything worked successfully, you should be able to view your site and see updated changes.&lt;/p&gt; &lt;h4 id&#x3D;&quot;add-ssh-key&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#add-ssh-key&quot;&gt;&lt;/a&gt;Add SSH key&lt;/h4&gt; &lt;p&gt;Don&amp;apos;t like typing your username and password every time you deploy? You can use a public SSH key to authenticate every time you do your push to deploy. If you haven&amp;apos;t already generated your SSH keys, you can &lt;a href&#x3D;&quot;https://help.github.com/articles/generating-ssh-keys/&quot;&gt;follow this guide through step 2&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;From there, you can simply copy your public key to your server.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-bash&quot;&gt;cat ~/.ssh/id_rsa.pub | ssh user@example.com &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;cat &amp;gt;&amp;gt; ~/.ssh/authorized_keys&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;What if you could automate your deployments? You can continue on reading on how you can enhance the push to deploy by making your deployments &lt;a href&#x3D;&quot;/automated-deploys-with-travis&quot;&gt;completely automated with Travis CI&lt;/a&gt;.&lt;/p&gt;</content></entry><entry><title>Bring on a new scurker.com</title><link href="https://scurker.com/bring-on-a-new-scurker-com"/><id>https://scurker.com/bring-on-a-new-scurker-com</id><updated>2014-12-14T00:00:00+00:00</updated><content type="html">&lt;p&gt;Welcome to the redesign and relaunch of scurker.com! It&amp;apos;s been far too long in my professional career that I have neglected this site, and felt that a new fresh coat of paint was long overdue.&lt;/p&gt; &lt;p&gt;It&amp;apos;s also been three years since I have contributed anything back to the community, and part of the goal for this relaunch is to better share what I know and have learned.&lt;/p&gt; &lt;h3 id&#x3D;&quot;so-long-wordpress&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#so-long-wordpress&quot;&gt;&lt;/a&gt;So Long Wordpress!&lt;/h3&gt; &lt;p&gt;Wordpress was a good start, but has finally outlived its usefulness and I&amp;apos;ve moved on to greener pastures. I wanted something much more lightweight and with more friendly editing. I had initially looked at &lt;a href&#x3D;&quot;http://ghost.org&quot;&gt;ghost&lt;/a&gt; along with a few other blogging platforms, but eventually decided that I didn&amp;apos;t want to be encumbered by unnecessary overhead of yet another blog platform.&lt;/p&gt; &lt;h3 id&#x3D;&quot;hello-wintersmith&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#hello-wintersmith&quot;&gt;&lt;/a&gt;Hello Wintersmith&lt;/h3&gt; &lt;p&gt;Bring on &lt;a href&#x3D;&quot;http://wintersmith.io/&quot;&gt;wintersmith&lt;/a&gt;, a nodejs static site generator. I don&amp;apos;t hate myself, so I also am using &lt;a href&#x3D;&quot;https://github.com/tnguyen14/wintersmith-handlebars&quot;&gt;wintersmith handlebars&lt;/a&gt; over the built in Jade template engine. For my sanity and easier editing I can write every post or page in markdown - which wintersmith will automatically convert.&lt;/p&gt; &lt;h3 id&#x3D;&quot;dependencies&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#dependencies&quot;&gt;&lt;/a&gt;Dependencies&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;&lt;a href&#x3D;&quot;http://wintersmith.io/&quot;&gt;wintersmith&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;https://github.com/tnguyen14/wintersmith-handlebars&quot;&gt;wintersmith handlebars&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;http://gruntjs.com&quot;&gt;grunt&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href&#x3D;&quot;http://www.google.com/fonts/specimen/Noto+Sans&quot;&gt;noto sans font&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;There&amp;apos;s some slightly modified plugins to wintersmith to allow for article to article pagination and a more sensible permalink structure.&lt;/p&gt; &lt;h3 id&#x3D;&quot;no-more-jquery&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#no-more-jquery&quot;&gt;&lt;/a&gt;No more jQuery&lt;/h3&gt; &lt;p&gt;I&amp;apos;m a big fan of jQuery, but I have been &lt;a href&#x3D;&quot;http://youmightnotneedjquery.com/&quot;&gt;slowly moving away from having jQuery&lt;/a&gt; as a dependency unless absolutely necessary. So you won&amp;apos;t see very much jQuery used here.&lt;/p&gt; &lt;h3 id&#x3D;&quot;open-sourced&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#open-sourced&quot;&gt;&lt;/a&gt;Open Sourced&lt;/h3&gt; &lt;p&gt;I&amp;apos;ve learned a lot through open source projects, and have spoken many times about the importance of open source. However, my own blog I kept private and didn&amp;apos;t share what I knew. I figured it&amp;apos;s time to start putting money where my mouth is and release the source for this site. You can check out everything on &lt;a href&#x3D;&quot;http://github.com/scurker/scurker.com&quot;&gt;github&lt;/a&gt;. If you come across any issues, be sure to &lt;a href&#x3D;&quot;https://github.com/scurker/scurker.com/issues&quot;&gt;let me know&lt;/a&gt;.&lt;/p&gt;</content></entry><entry><title>Go Mobile at TechMixer University</title><link href="https://scurker.com/go-mobile-at-techmixer-university"/><id>https://scurker.com/go-mobile-at-techmixer-university</id><updated>2011-09-25T00:00:00+00:00</updated><content type="html">&lt;p&gt;I will be presenting a session on mobile web development this coming Tuesday, on September 28th. Slides will be posted shortly after the session is finished.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Learn about recent trends regarding the mobile web&lt;/li&gt; &lt;li&gt;&amp;quot;Rethink&amp;quot; developing for mobile&lt;/li&gt; &lt;li&gt;Dive into mobile touch events and more!&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Couldn&amp;apos;t make the session? View the slides online at &lt;a href&#x3D;&quot;http://slides.scurker.com/gomobile&quot;&gt;http://slides.scurker.com/gomobile&lt;/a&gt;.&lt;/p&gt; &lt;h3 id&#x3D;&quot;techmixer-university&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#techmixer-university&quot;&gt;&lt;/a&gt;TechMixer University&lt;/h3&gt; &lt;p&gt;TechMixer University is an annual one-day conference that offers a full day of free technology training. This Birmingham, Alabama event is attended by the area&amp;#x2019;s brightest and enriched technical professionals, including developers, database professionals, project managers, network professionals, IT directors/managers and C-level executives.&lt;/p&gt; &lt;p&gt;&lt;a href&#x3D;&quot;http://www.techbirmingham.com/university/&quot;&gt;http://www.techbirmingham.com/university/&lt;/a&gt;&lt;/p&gt;</content></entry><entry><title>Amazon Trade-in Value Tracker</title><link href="https://scurker.com/amazon-trade-in-value-tracker"/><id>https://scurker.com/amazon-trade-in-value-tracker</id><updated>2011-04-13T00:00:00+00:00</updated><content type="html">&lt;p&gt;This was a project that actually begin back in the summer of &amp;apos;09. At the time Amazon had introduced a trade-in system with some pretty tempting promotions. However, there were limitations in that you could only see the most recent trade-in value with no ability for a history or a way to detect changes. Thus, the ativ tracker was born.&lt;/p&gt; &lt;p&gt;Over a year later and with nearly 700,000 values tracked, the tracker is still chugging along but needed a new coat of paint. It&amp;apos;s been updated with a new theme, some background improvements, better mobile optimizations, and charting utilizing &lt;a href&#x3D;&quot;http://raphaeljs.com/&quot;&gt;Rapha&amp;#xEB;lJS&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;A lot of sweat and hard work was put into this project to make it easy to track trade-in values. So if you have some old games sitting in your closet, why not consider &lt;a href&#x3D;&quot;http://tivtrackr.com&quot;&gt;checking out the tracker&lt;/a&gt; and turning your games into Amazon credit?&lt;/p&gt;</content></entry><entry><title>Scurker Levels Up</title><link href="https://scurker.com/scurker-levels-up"/><id>https://scurker.com/scurker-levels-up</id><updated>2010-12-14T00:00:00+00:00</updated><content type="html">&lt;p&gt;Welcome to the new and improved scurker.com! I&amp;apos;d never felt comfortable with my previous design and never really felt inspired by it. There had been some things that I had felt had been missing, and the site lacked a lot of flexibility I was looking for. Shortly after my previous design had been launched, I begin work on this iteration giving time for things to settle in. What has changed?&lt;/p&gt; &lt;h3 id&#x3D;&quot;standards-are-dead&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#standards-are-dead&quot;&gt;&lt;/a&gt;Standards Are Dead?&lt;/h3&gt; &lt;p&gt;Well technically, no. Previously I have been using XHTML 1.0 strict, but have now switched to an HTML 5 doctype, which is simple as &lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/code&gt;. The majority of the features I plan on using are quite usable across most major browsers, so I see little reason not to make the switch.&lt;/p&gt; &lt;h3 id&#x3D;&quot;portfolio&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#portfolio&quot;&gt;&lt;/a&gt;Portfolio&lt;/h3&gt; &lt;p&gt;Thanks to features added with Wordpress 3.0, this has given me the ability to update new additions to the portfolio that much easier!&lt;/p&gt; &lt;h3 id&#x3D;&quot;no-more-boring-fonts&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#no-more-boring-fonts&quot;&gt;&lt;/a&gt;No More Boring Fonts!&lt;/h3&gt; &lt;p&gt;Goodbye Trebuchet MS, hello @font-face! Web fonts have wide support in a majority of browsers, so why not take advantage of it? The &lt;a href&#x3D;&quot;http://code.google.com/webfonts&quot;&gt;Google Font API&lt;/a&gt; is a great resource for doing so.&lt;/p&gt; &lt;p&gt;This is only a portion of the site as the rest should come around the corner of the holidays. Please feel free to leave any comments or suggestions below.&lt;/p&gt;</content></entry><entry><title>Particle Generator using HTML5&#x27;s Canvas</title><link href="https://scurker.com/particle-generator-using-html5s-canvas"/><id>https://scurker.com/particle-generator-using-html5s-canvas</id><updated>2010-06-04T00:00:00+00:00</updated><content type="html">&lt;p&gt;Particle effects are pretty awesome. Particles by themselves are fairly simple, but by generating multitudes of particles with set variables you can create a range of effects such as fire, smoke, or water. A particle generator or emitter allows you to adjust the variables giving you control over the types of effects you can generate.&lt;/p&gt; &lt;p&gt;I&amp;apos;ve been working on another project that needed a particle generator, thus this demonstration was born.&lt;/p&gt; &lt;p&gt;There are several presets I&amp;apos;ve included, but you can easily generate new types of effects by playing around with the available variables on the presets.&lt;/p&gt; &lt;p&gt;The demo does not give you access to everything so in order to create more fine tuned options, here&amp;apos;s all the currently available variables:&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;{ &lt;span class&#x3D;&quot;attr&quot;&gt;shape&lt;/span&gt;: &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;circle&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// square or circle&lt;/span&gt; velocity: &lt;span class&#x3D;&quot;keyword&quot;&gt;new&lt;/span&gt; Vector({&lt;span class&#x3D;&quot;attr&quot;&gt;y&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;-1&lt;/span&gt;}), &lt;span class&#x3D;&quot;comment&quot;&gt;// movement vector; only y is used&lt;/span&gt; xVariance: &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// +/- start x position (random)&lt;/span&gt; yVariance: &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// +/- start y position (random)&lt;/span&gt; spawnSpeed: &lt;span class&#x3D;&quot;number&quot;&gt;25&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// # particles spawned per cycle&lt;/span&gt; generations: &lt;span class&#x3D;&quot;number&quot;&gt;100000&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// # of cycles to run for&lt;/span&gt; maxParticles: &lt;span class&#x3D;&quot;number&quot;&gt;500&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// max # of particles allowed on screen&lt;/span&gt; size: &lt;span class&#x3D;&quot;number&quot;&gt;20&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// size of particles&lt;/span&gt; sizeVariance: &lt;span class&#x3D;&quot;number&quot;&gt;5&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// +/- size of particles (random)&lt;/span&gt; life: &lt;span class&#x3D;&quot;number&quot;&gt;30&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// # of cycles a particle can live&lt;/span&gt; lifeVariance: &lt;span class&#x3D;&quot;number&quot;&gt;10&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// +/- lifetime of particle (random)&lt;/span&gt; direction: &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// initial start direction&lt;/span&gt; directionVariance: &lt;span class&#x3D;&quot;number&quot;&gt;15&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// +/- direction (random)&lt;/span&gt; color: &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#fff&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// can be hex code or rgb&lt;/span&gt; opacity: &lt;span class&#x3D;&quot;number&quot;&gt;1&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// particle opacity&lt;/span&gt; onDraw: &lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class&#x3D;&quot;params&quot;&gt;p&lt;/span&gt;) &lt;/span&gt;{ &lt;span class&#x3D;&quot;comment&quot;&gt;// onDraw passes in the current particle and is called before each&lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;// particle is displayed on the screen. This function is used in&lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;// several of the presets to adjust the color or opacity given&lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;// the particle&amp;apos;s current age and lifespan.&lt;/span&gt; } }&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;If you are using Firefox and Firebug, you can create your own objects and update the particle generator by using &lt;code&gt;particles.update(myObject);&lt;/code&gt; via the command line.&lt;/p&gt; &lt;p&gt;As usual, HTML5 and Canvas is not currently supported by IE7/IE8, so you&amp;apos;ll need to use another browser in order for this to work. The demo has been tested in Firefox, Safari and Chrome, but I highly recommend using Chrome for the demo as it seems to run the most efficient.&lt;/p&gt; &lt;p&gt;&lt;a href&#x3D;&quot;/projects/particles&quot;&gt;On to the demo!&lt;/a&gt; Or alternatively, view the source &lt;a href&#x3D;&quot;/projects/particles/js/particle.js&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content></entry><entry><title>Javascript Clock using HTML5 and Canvas</title><link href="https://scurker.com/javascript-clock-using-html5-and-canvas"/><id>https://scurker.com/javascript-clock-using-html5-and-canvas</id><updated>2010-04-20T00:00:00+00:00</updated><content type="html">&lt;script src&#x3D;&quot;//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js&quot;&gt;&lt;/script&gt; &lt;script type&#x3D;&quot;text/javascript&quot; src&#x3D;&quot;/projects/jclock/jclock.js&quot;&gt;&lt;/script&gt; &lt;script type&#x3D;&quot;text/javascript&quot;&gt; $(window).ready(function() { new jClock(&#x27;/projects/jclock/clock.png&#x27;, $(&#x27;canvas&#x27;).get(0)); }); &lt;/script&gt; &lt;style type&#x3D;&quot;text/css&quot;&gt; #jclock { padding-top: 15px; padding-right: 15px; float: left; } &lt;/style&gt; &lt;p&gt;I&amp;apos;ve been finding myself becoming more interested in what HTML5 can do. As I see it HTML5 stands to be a potential replacement for flash, in addition to the features and interactivity that are made available by various javascript frameworks out there.&lt;/p&gt; &lt;p&gt;A good starting point would be to start off with something simple, i.e. a clock. Here&amp;apos;s a sample project I threw together to help make myself more familiar with HTML5&amp;apos;s canvas.&lt;/p&gt; &lt;div id&#x3D;&quot;jclock&quot;&gt; &lt;canvas height&#x3D;&quot;125&quot; width&#x3D;&quot;125&quot;&gt;&lt;img src&#x3D;&quot;/projects/jclock/clock.png&quot; alt&#x3D;&quot;HTML5 isn&amp;apos;t supported!&quot; title&#x3D;&quot;HTML5 isn&amp;apos;t supported!&quot;&gt;&lt;/canvas&gt; &lt;/div&gt; &lt;p&gt;The clock you see on the left is written completely in javascript and takes advantage of &lt;a href&#x3D;&quot;http://dev.w3.org/html5/spec/Overview.html#the-canvas-element&quot;&gt;HTML5 and the canvas element&lt;/a&gt; -- no flash necessary.&lt;/p&gt; &lt;p&gt;If you see a blank clock face with no hands, that means that your browser does not support HTML5. You will need to be using the latest version of &lt;a href&#x3D;&quot;http://www.google.com/chrome&quot;&gt;Chrome&lt;/a&gt;, &lt;a href&#x3D;&quot;http://getfirefox.com&quot;&gt;Firefox&lt;/a&gt;, &lt;a href&#x3D;&quot;http://opera.com&quot;&gt;Opera&lt;/a&gt; or &lt;a href&#x3D;&quot;http://apple.com/safari&quot;&gt;Safari&lt;/a&gt; in order for the clock to work. IE does not currently natively support the canvas element.&lt;/p&gt; &lt;p&gt;There are &lt;a href&#x3D;&quot;https://developer.mozilla.org/en/Canvas_tutorial&quot;&gt;several&lt;/a&gt; &lt;a href&#x3D;&quot;http://developer.apple.com/mac/library/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/Canvas.html&quot;&gt;good&lt;/a&gt; &lt;a href&#x3D;&quot;http://dev.opera.com/articles/view/html-5-canvas-the-basics/&quot;&gt;canvas&lt;/a&gt; &lt;a href&#x3D;&quot;http://carsonified.com/blog/dev/html-5-dev/how-to-draw-with-html-5-canvas/&quot;&gt;tutorials&lt;/a&gt; out there so please check those if you want a more in-depth introduction to HTML5&amp;apos;s canvas element.&lt;/p&gt; &lt;p&gt;In order to use this clock, you&amp;apos;ll need to setup your canvas element:&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-html&quot;&gt;&lt;span class&#x3D;&quot;tag&quot;&gt;&amp;lt;&lt;span class&#x3D;&quot;name&quot;&gt;canvas&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;id&lt;/span&gt;&#x3D;&lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;jclock&amp;quot;&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;height&lt;/span&gt;&#x3D;&lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;125&amp;quot;&lt;/span&gt; &lt;span class&#x3D;&quot;attr&quot;&gt;width&lt;/span&gt;&#x3D;&lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;125&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt; Content or message to display if the browser does not support Canvas/HTML5. &lt;span class&#x3D;&quot;tag&quot;&gt;&amp;lt;/&lt;span class&#x3D;&quot;name&quot;&gt;canvas&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Initializing the clock:&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;$(&lt;span class&#x3D;&quot;built_in&quot;&gt;window&lt;/span&gt;).load(&lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class&#x3D;&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{ &lt;span class&#x3D;&quot;keyword&quot;&gt;new&lt;/span&gt; jClock(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;my-clock-face-image.png&amp;apos;&lt;/span&gt;, $(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#jclock&amp;apos;&lt;/span&gt;).get(&lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;)); });&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;You can also pass in additional options to change items such as the hand colors, or image size. Here&amp;apos;s the defaults as defined in the plugin:&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-javascript&quot;&gt;&lt;span class&#x3D;&quot;comment&quot;&gt;// override default options:&lt;/span&gt; &lt;span class&#x3D;&quot;comment&quot;&gt;// i.e. new jClock(&amp;apos;image.png&amp;apos;, $(&amp;apos;#canvas&amp;apos;).get(0), {shadow: false});&lt;/span&gt; jClock.defaults &#x3D; { &lt;span class&#x3D;&quot;attr&quot;&gt;height&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;125&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// default height&lt;/span&gt; width: &lt;span class&#x3D;&quot;number&quot;&gt;125&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// default width&lt;/span&gt; secondHand: &lt;span class&#x3D;&quot;literal&quot;&gt;true&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// show the second hand&lt;/span&gt; shadow: &lt;span class&#x3D;&quot;literal&quot;&gt;true&lt;/span&gt;, &lt;span class&#x3D;&quot;comment&quot;&gt;// display shadows across all hands&lt;/span&gt; second: { &lt;span class&#x3D;&quot;comment&quot;&gt;// second hand style options&lt;/span&gt; color: &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#f00&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;width&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;2&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;start&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;-10&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;end&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;35&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;alpha&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;1&lt;/span&gt; }, &lt;span class&#x3D;&quot;attr&quot;&gt;minute&lt;/span&gt;: { &lt;span class&#x3D;&quot;comment&quot;&gt;// minute hand style options&lt;/span&gt; color: &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#fff&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;width&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;3&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;start&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;-7&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;end&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;30&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;alpha&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;1&lt;/span&gt; }, &lt;span class&#x3D;&quot;attr&quot;&gt;hour&lt;/span&gt;: { &lt;span class&#x3D;&quot;comment&quot;&gt;// hour hand style options&lt;/span&gt; color: &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;#fff&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;width&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;4&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;start&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;-7&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;end&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;20&lt;/span&gt;, &lt;span class&#x3D;&quot;attr&quot;&gt;alpha&lt;/span&gt;: &lt;span class&#x3D;&quot;number&quot;&gt;1&lt;/span&gt; } };&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Feel free to download the source code and play around with it, or ask any questions you may have in the comments below.&lt;/p&gt; &lt;p&gt;&lt;a href&#x3D;&quot;/projects/jclock/jclock.js&quot;&gt;Download jclock.js (2.4k)&lt;/a&gt;&lt;/p&gt;</content></entry><entry><title>Migration from Drupal 6.x to Wordpress 2.9x</title><link href="https://scurker.com/migration-from-drupal-6-x-to-wordpress-2-9x"/><id>https://scurker.com/migration-from-drupal-6-x-to-wordpress-2-9x</id><updated>2010-02-26T00:00:00+00:00</updated><content type="html">&lt;p&gt;I recently found myself wanting to move my &lt;a href&#x3D;&quot;blog.scurker.com&quot;&gt;personal blog&lt;/a&gt; from &lt;a href&#x3D;&quot;http://drupal.org&quot;&gt;Drupal 6.x&lt;/a&gt; to &lt;a href&#x3D;&quot;Wordpress&quot;&gt;Wordpress&lt;/a&gt; for various reasons. I primarily followed &lt;a href&#x3D;&quot;http://socialcmsbuzz.com/convert-import-a-drupal-6-based-website-to-wordpress-v27-20052009&quot;&gt;this tutorial&lt;/a&gt;, but wanted to outline some additional information in the transfer.&lt;/p&gt; &lt;h3 id&#x3D;&quot;database-conversion-table&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#database-conversion-table&quot;&gt;&lt;/a&gt;Database Conversion Table&lt;/h3&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Drupal 6.x Table(s)&lt;/th&gt; &lt;th&gt;Wordpress 2.9x Equivalent&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;term_data, term_hierarchy&lt;/td&gt; &lt;td&gt;wp_terms&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;node, node_revisions&lt;/td&gt; &lt;td&gt;wp_posts&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;term_node&lt;/td&gt; &lt;td&gt;wp_term_relationships&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;comments&lt;/td&gt; &lt;td&gt;wp_comments&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;h3 id&#x3D;&quot;truncate-wordpress-tables&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#truncate-wordpress-tables&quot;&gt;&lt;/a&gt;Truncate Wordpress Tables&lt;/h3&gt; &lt;p&gt;First, I needed to remove any data that is currently in certain wordpress tables so I could work with a fresh slate.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; By default when you install wordpress all tables are prefixed with &lt;code&gt;wp_&lt;/code&gt; unless you changed it to something else. The below queries will need to be modified if you used anything else other than &lt;code&gt;wp_&lt;/code&gt;.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;TRUNCATE&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;TABLE&lt;/span&gt; wp_comments; &lt;span class&#x3D;&quot;keyword&quot;&gt;TRUNCATE&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;TABLE&lt;/span&gt; wp_postmeta; &lt;span class&#x3D;&quot;keyword&quot;&gt;TRUNCATE&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;TABLE&lt;/span&gt; wp_posts; &lt;span class&#x3D;&quot;keyword&quot;&gt;TRUNCATE&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;TABLE&lt;/span&gt; wp_term_relationships; &lt;span class&#x3D;&quot;keyword&quot;&gt;TRUNCATE&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;TABLE&lt;/span&gt; wp_term_taxonomy; &lt;span class&#x3D;&quot;keyword&quot;&gt;TRUNCATE&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;TABLE&lt;/span&gt; wp_terms;&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;import-taxonomy-terms&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#import-taxonomy-terms&quot;&gt;&lt;/a&gt;Import Taxonomy Terms&lt;/h3&gt; &lt;p&gt;The next sets of queries imports taxonomy terms.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; Table names pre-pended with &lt;code&gt;drupal.&lt;/code&gt; needs to be the actual name of your drupal database. You will need to change this to whatever you have your drupal database named.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;INSERT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;INTO&lt;/span&gt; wp_terms (term_id, &lt;span class&#x3D;&quot;keyword&quot;&gt;name&lt;/span&gt;, slug, term_group) &lt;span class&#x3D;&quot;keyword&quot;&gt;SELECT&lt;/span&gt; d.tid, d.name, &lt;span class&#x3D;&quot;keyword&quot;&gt;REPLACE&lt;/span&gt;(&lt;span class&#x3D;&quot;keyword&quot;&gt;LOWER&lt;/span&gt;(d.name), &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos; &amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;-&amp;apos;&lt;/span&gt;), &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;FROM&lt;/span&gt; drupal.term_data d &lt;span class&#x3D;&quot;keyword&quot;&gt;INNER&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;JOIN&lt;/span&gt; drupal.term_hierarchy h &lt;span class&#x3D;&quot;keyword&quot;&gt;USING&lt;/span&gt;(tid);&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;By default, Wordpress has several taxonomy types available; &lt;code&gt;categories&lt;/code&gt;, &lt;code&gt;post_tag&lt;/code&gt;, and &lt;code&gt;link_category&lt;/code&gt;. In my Drupal instance I used taxonomy primarily as tags, but you may have a different need. You may need to modify the 3rd line in the below query depending on how you want taxonomies imported:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;em&gt;Categories&lt;/em&gt;: &lt;code&gt;category&lt;/code&gt;&lt;/li&gt; &lt;li&gt;&lt;em&gt;Link Categories&lt;/em&gt;: &lt;code&gt;link_category&lt;/code&gt;&lt;/li&gt; &lt;li&gt;&lt;em&gt;Post Tags&lt;/em&gt;: &lt;code&gt;post_tag&lt;/code&gt;&lt;/li&gt; &lt;/ul&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;INSERT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;INTO&lt;/span&gt; wp_term_taxonomy (term_taxonomy_id, term_id, taxonomy, description, &lt;span class&#x3D;&quot;keyword&quot;&gt;parent&lt;/span&gt;) &lt;span class&#x3D;&quot;keyword&quot;&gt;SELECT&lt;/span&gt; d.tid, d.tid, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;post_tag&amp;apos;&lt;/span&gt;, d.description, h.parent &lt;span class&#x3D;&quot;keyword&quot;&gt;FROM&lt;/span&gt; drupal.term_data d &lt;span class&#x3D;&quot;keyword&quot;&gt;INNER&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;JOIN&lt;/span&gt; drupal.term_hierarchy h &lt;span class&#x3D;&quot;keyword&quot;&gt;USING&lt;/span&gt;(tid);&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;import-post-content&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#import-post-content&quot;&gt;&lt;/a&gt;Import Post Content&lt;/h3&gt; &lt;p&gt;Drupal allows for custom post types, while as of Wordpress 2.9x, custom post types are only available via plugins. You can use the below query unmodified and it will convert all stories to posts, and everything else will transfer over as is. If you need to convert additional post types, you can add additional case statements.&lt;/p&gt; &lt;p&gt;Example: &lt;code&gt;WHEN &amp;apos;book&amp;apos; THEN &amp;apos;post&amp;apos;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I also adjusted the query so that &amp;apos;post_date_gmt&amp;apos; would be populated correctly based on my GMT offset of -6:00 (Central Time). If you are in a different timezone you will need to adjust &lt;code&gt;FROM_UNIXTIME(created+21600)&lt;/code&gt; to subtract or add correctly based on your location.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;INSERT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;INTO&lt;/span&gt; wp_posts (&lt;span class&#x3D;&quot;keyword&quot;&gt;id&lt;/span&gt;, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_name, post_type, post_modified) &lt;span class&#x3D;&quot;keyword&quot;&gt;SELECT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;DISTINCT&lt;/span&gt; n.nid, FROM_UNIXTIME(created), FROM_UNIXTIME(created+&lt;span class&#x3D;&quot;number&quot;&gt;21600&lt;/span&gt;), &lt;span class&#x3D;&quot;keyword&quot;&gt;body&lt;/span&gt;, n.title, teaser, &lt;span class&#x3D;&quot;keyword&quot;&gt;LOWER&lt;/span&gt;(n.title), (&lt;span class&#x3D;&quot;keyword&quot;&gt;CASE&lt;/span&gt; n.type &lt;span class&#x3D;&quot;keyword&quot;&gt;WHEN&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;story&amp;apos;&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;THEN&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;post&amp;apos;&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;ELSE&lt;/span&gt; n.type &lt;span class&#x3D;&quot;keyword&quot;&gt;END&lt;/span&gt;) &lt;span class&#x3D;&quot;keyword&quot;&gt;as&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;type&lt;/span&gt;, FROM_UNIXTIME(&lt;span class&#x3D;&quot;keyword&quot;&gt;changed&lt;/span&gt;) &lt;span class&#x3D;&quot;keyword&quot;&gt;FROM&lt;/span&gt; drupal.node n, drupal.node_revisions r &lt;span class&#x3D;&quot;keyword&quot;&gt;WHERE&lt;/span&gt; n.vid &#x3D; r.vid;&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;import-post-and-taxonomy-relationships&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#import-post-and-taxonomy-relationships&quot;&gt;&lt;/a&gt;Import Post and Taxonomy Relationships&lt;/h3&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;INSERT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;INTO&lt;/span&gt; wp_term_relationships (object_id, term_taxonomy_id) &lt;span class&#x3D;&quot;keyword&quot;&gt;SELECT&lt;/span&gt; nid, tid &lt;span class&#x3D;&quot;keyword&quot;&gt;FROM&lt;/span&gt; drupal.term_node;&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;category-count-updating&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#category-count-updating&quot;&gt;&lt;/a&gt;Category Count Updating&lt;/h3&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;UPDATE&lt;/span&gt; wp_term_taxonomy tt &lt;span class&#x3D;&quot;keyword&quot;&gt;SET&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;count&lt;/span&gt; &#x3D; ( &lt;span class&#x3D;&quot;keyword&quot;&gt;SELECT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;COUNT&lt;/span&gt;(tr.object_id) &lt;span class&#x3D;&quot;keyword&quot;&gt;FROM&lt;/span&gt; wp_term_relationships tr &lt;span class&#x3D;&quot;keyword&quot;&gt;WHERE&lt;/span&gt; tr.term_taxonomy_id &#x3D; tt.term_taxonomy_id );&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;import-comments&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#import-comments&quot;&gt;&lt;/a&gt;Import Comments&lt;/h3&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;INSERT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;INTO&lt;/span&gt; wp_comments (comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url, comment_approved) &lt;span class&#x3D;&quot;keyword&quot;&gt;SELECT&lt;/span&gt; nid, FROM_UNIXTIME(&lt;span class&#x3D;&quot;built_in&quot;&gt;timestamp&lt;/span&gt;), &lt;span class&#x3D;&quot;keyword&quot;&gt;comment&lt;/span&gt;, &lt;span class&#x3D;&quot;keyword&quot;&gt;thread&lt;/span&gt;, &lt;span class&#x3D;&quot;keyword&quot;&gt;name&lt;/span&gt;, mail, homepage, &lt;span class&#x3D;&quot;keyword&quot;&gt;status&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;FROM&lt;/span&gt; drupal.comments;&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;update-comment-count&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#update-comment-count&quot;&gt;&lt;/a&gt;Update Comment Count&lt;/h3&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-sql&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;UPDATE&lt;/span&gt; wp_posts &lt;span class&#x3D;&quot;keyword&quot;&gt;SET&lt;/span&gt; comment_count &#x3D; (&lt;span class&#x3D;&quot;keyword&quot;&gt;SELECT&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;COUNT&lt;/span&gt;(comment_post_id) &lt;span class&#x3D;&quot;keyword&quot;&gt;FROM&lt;/span&gt; wp_comments &lt;span class&#x3D;&quot;keyword&quot;&gt;WHERE&lt;/span&gt; wp_posts.id &#x3D; wp_comments.comment_post_id);&lt;/code&gt;&lt;/pre&gt; &lt;h3 id&#x3D;&quot;update-post-slugs&quot;&gt;&lt;a class&#x3D;&quot;anchor-link&quot; aria-hidden&#x3D;&quot;true&quot; href&#x3D;&quot;#update-post-slugs&quot;&gt;&lt;/a&gt;Update Post Slugs&lt;/h3&gt; &lt;p&gt;Drupal&amp;apos;s URL aliases is equivalent to Wordpress&amp;apos; permalinks. Drupal has a much more aggressive title sanitation than Wordpress. I wanted the ability to keep my titles the same for SEO reasons when migrating over to Wordpress.&lt;/p&gt; &lt;p&gt;In order to keep my old titles, I need to hook into Wordpress&amp;apos; &lt;a href&#x3D;&quot;http://codex.wordpress.org/Function_Reference/sanitize_title&quot;&gt;title sanitation&lt;/a&gt; with similar rules to Drupal. The below code will need to be placed somewhere in the &lt;code&gt;functions.php&lt;/code&gt; file of your current theme.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-php&quot;&gt;add_filter(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;sanitize_title&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;my_sanitize_title&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;function&quot;&gt;&lt;span class&#x3D;&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class&#x3D;&quot;title&quot;&gt;my_sanitize_title&lt;/span&gt;&lt;span class&#x3D;&quot;params&quot;&gt;($title)&lt;/span&gt; &lt;/span&gt;{ $title &#x3D; preg_replace(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;/\b(a|an|as|at|before|but|by|for|from|is|in|into|like|of|off|on|onto|per|since|than|the|this|that|to|up|via|with)\b/i&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;&amp;apos;&lt;/span&gt;, $title); $title &#x3D; preg_replace(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;/-+/&amp;apos;&lt;/span&gt;, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;-&amp;apos;&lt;/span&gt;, $title); $title &#x3D; trim($title, &lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;-&amp;apos;&lt;/span&gt;); &lt;span class&#x3D;&quot;keyword&quot;&gt;return&lt;/span&gt; $title; }&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;You will need to save the below code to a file i.e. &amp;quot;fix-slugs.php&amp;quot; in your main Wordpress directory and run it through your browser.&lt;/p&gt; &lt;pre&gt;&lt;code class&#x3D;&quot;language-php&quot;&gt;&lt;span class&#x3D;&quot;meta&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span class&#x3D;&quot;keyword&quot;&gt;require_once&lt;/span&gt;(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;apos;wp-load.php&amp;apos;&lt;/span&gt;); $posts &#x3D; $wpdb-&amp;gt;get_results( &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;SELECT ID, post_title, post_name FROM $wpdb-&amp;gt;posts&amp;quot;&lt;/span&gt; ); $count &#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;; $ignored &#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;; $errors &#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;; &lt;span class&#x3D;&quot;keyword&quot;&gt;foreach&lt;/span&gt;($posts &lt;span class&#x3D;&quot;keyword&quot;&gt;as&lt;/span&gt; $post) { &lt;span class&#x3D;&quot;keyword&quot;&gt;if&lt;/span&gt;(strcmp($slug &#x3D; sanitize_title($post-&amp;gt;post_title), $post-&amp;gt;post_name) !&#x3D;&#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;) { $wpdb-&amp;gt;show_errors(); &lt;span class&#x3D;&quot;keyword&quot;&gt;if&lt;/span&gt;(($result &#x3D; $wpdb-&amp;gt;query(&lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;UPDATE $wpdb-&amp;gt;posts SET post_name&#x3D;&amp;apos;$slug&amp;apos; WHERE ID&#x3D;$post-&amp;gt;ID&amp;quot;&lt;/span&gt;)) &#x3D;&#x3D;&#x3D; &lt;span class&#x3D;&quot;keyword&quot;&gt;false&lt;/span&gt;) { $errors++; } &lt;span class&#x3D;&quot;keyword&quot;&gt;elseif&lt;/span&gt;($result &#x3D;&#x3D;&#x3D; &lt;span class&#x3D;&quot;number&quot;&gt;0&lt;/span&gt;) { $ignore++; } &lt;span class&#x3D;&quot;keyword&quot;&gt;else&lt;/span&gt; { $count++; } } &lt;span class&#x3D;&quot;keyword&quot;&gt;else&lt;/span&gt; { $ignored++; } } &lt;span class&#x3D;&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;*$count post slug(s) sanitized.*&amp;lt;br /&amp;gt;&amp;quot;&lt;/span&gt;; &lt;span class&#x3D;&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;$ignored post(s) ignored.&amp;lt;br /&amp;gt;&amp;quot;&lt;/span&gt;; &lt;span class&#x3D;&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class&#x3D;&quot;string&quot;&gt;&amp;quot;$errors error(s).&amp;lt;br /&amp;gt;&amp;quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;If you were following along with &lt;a href&#x3D;&quot;http://socialcmsbuzz.com/convert-import-a-drupal-6-based-website-to-wordpress-v27-20052009/&quot;&gt;this tutorial&lt;/a&gt;, I&amp;apos;ve made a few changes based on my Drupal setup using &lt;a href&#x3D;&quot;http://codex.wordpress.org/Database_Description&quot;&gt;Wordpress database description&lt;/a&gt; as a reference when I ran into issues. There may be some additional steps to be completed if you uploaded images through Drupal&amp;apos;s interface, but the above queries were able to successfully migrate my data from Drupal to Wordpress.&lt;/p&gt;</content></entry><entry><title>A new beginning</title><link href="https://scurker.com/a-new-beginning"/><id>https://scurker.com/a-new-beginning</id><updated>2010-01-19T00:00:00+00:00</updated><content type="html">&lt;p&gt;You&amp;apos;ve undoubtedly reached this site through either word of mouth, or via my &lt;a href&#x3D;&quot;http://blog.scurker.com&quot;&gt;personal blog&lt;/a&gt;, but I&amp;apos;d like to formally welcome you to the new scurker.com! I&amp;apos;ve been hard at work over the past week in order to get everything up and running and am happy to finally be at this point.&lt;/p&gt; &lt;p&gt;One of my big reasons for rolling over to a new design was the limitations my old site was giving me. I wanted to have a new fresher design in addition to having more flexibility with the content on the site. Now with the addition of &lt;a href&#x3D;&quot;http://wordpress.org&quot;&gt;wordpress&lt;/a&gt;, I can easily outline new projects or post about some dramatic revolution in web design. In addition the new site will help me give a better showcase for my skills and abilities for any future clients and/or employers.&lt;/p&gt; &lt;p&gt;You are not seeing the final version of this roll-out, but features will slowly be added as I get time. Please feel free to post a comment if you notice any issues, or &lt;a href&#x3D;&quot;/about&quot;&gt;contact me&lt;/a&gt; if you have any opportunities you would like to discuss.&lt;/p&gt;</content></entry></feed>