<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Andy’s Scribbles</title>
  
  <subtitle>your JavaScript is showing.</subtitle>
  <link href="https://andy.vanwago.net/atom.xml" rel="self"/>
  
  <link href="https://andy.vanwago.net/"/>
  <updated>2019-05-30T16:23:49.228Z</updated>
  <id>https://andy.vanwago.net/</id>
  
  <author>
    <name>Andy VanWagoner</name>
    
  </author>
  
  <generator uri="https://hexo.io/">Hexo</generator>
  
  <entry>
    <title>Who am I?</title>
    <link href="https://andy.vanwago.net/2018/05/08/who-am-i/"/>
    <id>https://andy.vanwago.net/2018/05/08/who-am-i/</id>
    <published>2018-05-08T20:53:58.000Z</published>
    <updated>2019-05-30T16:23:49.228Z</updated>
    
    <content type="html"><![CDATA[<p>Figuring out who we are and how to understand, describe, and present that to other people is a tough challenge. People are complex and dynamic, and rarely fit nicely into some category. Do the things we call ourselves influence who we are?</p><p>We are <del>all</del> usually given an identifier at birth, called a name. They aren’t necessarily unique, but often close enough. I am “Andrew Henry Van Wagoner”. This name is supposed to represent all of me.</p><p>My name isn’t necessarily static, though. My family &amp; friends have been calling my “Andy” for longer than I can remember, and most of my documents use “VanWagoner” (no space) to prevent software from tokenizing my last name incorrectly. My wife, like many people, legally changed her name when we got married. Though my name has an assigned meaning to it (manly), I doubt most people give it any thought beyond inferring my gender.</p><p>When we introduce ourselves, we rarely lead with our full names. “I’m Andy.” Sometimes we include our job function, department, or employer. “I’m Andy from Instructure.” This is where it starts to become more descriptive rather than identifying.</p><p>Once connected to the internet, we are given the opportunity to make up our own handle for ourselves. <a href="https://en.wikipedia.org/wiki/On_the_Internet,_nobody_knows_you&#39;re_a_dog" target="_blank" rel="noopener">On the internet, nobody knows you are a dog.</a> Am I “thewol” (meaning the warrior of light), or “imnd” (see what I did there?), or “boyz_ii_men_iv_ever”?</p><p>In 2005 I dropped my old “<a href="mailto:thewol@msn.com" target="_blank" rel="noopener">thewol@msn.com</a>“ email address for the beta Gmail service as “<a href="mailto:thetalecrafter@gmail.com" target="_blank" rel="noopener">thetalecrafter@gmail.com</a>“. I figured I was going to make a career out of writing fiction, so it would be a fun way of introducing myself on subsequent online services. “I’m thetalecrafter.” I don’t remember feeling much attached to my prior “thewol”, so shedding that identity was painless.</p><p>It didn’t take long though for my anticipation of a writing fiction career to turn into an actual writing <em>software</em> career. And for more than a decade, I have presented myself with the handle “thetalecrafter”, giving people the impression, you know, that I craft tales.</p><p>Justifying this situation to myself wasn’t too hard though, as I <em>did</em> have a book I worked on periodically. And the label I had given myself pushed on me more than anything else to keep this book draft around. Over the years, work on my tales went from occasional (once every few weeks) to practically never (once every few years), and the handle continued to insist that <em>this is who am</em>.</p><p>As I used more and more services online, my handle “thetalecrafter” only became more entrenched. Twitter, GitHub, keybase, etc.</p><p>During this same time my once exciting email provider, the “do no evil” Google, went from being the shining example of making cool things that make the web better, to the stalker who follows you around, and strong arms the competition into adopting their “standards”.</p><p>As I switched from Googling to searching on Duck Duck Go, and I looked to leave behind “thetalecrafter” which beyond being inaccurate, gave me guilt about being the right me, I opted to go back to the name I inherited from ancestors. No matter what else changes in my life, my actual name was always going to be a solid identifier. I registered the domain <code>vanwagoner.family</code> and setup a matching email address.</p><p>Alas, several services I rely on do not think <code>.family</code> is a valid way to end an email address. So for two years now, I have drug along “<a href="mailto:thetalecrafter@gmail.com" target="_blank" rel="noopener">thetalecrafter@gmail.com</a>“ as a backup address. I don’t craft tales, and I don’t like Google.</p><p>Finally a straw broke the camel’s back, and I decided it was time to really ditch thetalecrafter. The handle, the email address, and the website (this one). On a whim I was looking at domain names, and found that <code>vanwago.net</code> was available. That would be a solid alias for <code>vanwagoner.family</code>, using a TLD that even AOL recognizes. Once I had the domain, I figured it didn’t make a terrible handle either.</p><p>Hi, I’m “vanwagonet”. I’m not on Facebook or Twitter these days, but I am on <a href="https://github.com/vanwagonet" target="_blank" rel="noopener">GitHub</a> and <a href="https://www.linkedin.com/in/andrewvanwagoner" target="_blank" rel="noopener">LinkedIn</a>, and every now and then I write things down on <a href="https://andy.vanwago.net">this site</a>. I may <a href="/2015/07/25/jumping-the-fold/">spin some tales</a> <a href="/2015/06/23/breathless-in-a-new-world/">in the future</a>, but even if I don’t, I’ll still be Andy VanWagoner.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;Figuring out who we are and how to understand, describe, and present that to other people is a tough challenge. People are complex and dy</summary>
      
    
    
    
    <category term="General" scheme="https://andy.vanwago.net/categories/general/"/>
    
    
    <category term="web" scheme="https://andy.vanwago.net/tags/web/"/>
    
    <category term="internet" scheme="https://andy.vanwago.net/tags/internet/"/>
    
    <category term="Andrew" scheme="https://andy.vanwago.net/tags/andrew/"/>
    
    <category term="Google" scheme="https://andy.vanwago.net/tags/google/"/>
    
    <category term="Facebook" scheme="https://andy.vanwago.net/tags/facebook/"/>
    
    <category term="social" scheme="https://andy.vanwago.net/tags/social/"/>
    
  </entry>
  
  <entry>
    <title>Jumping the Fold</title>
    <link href="https://andy.vanwago.net/2015/07/25/jumping-the-fold/"/>
    <id>https://andy.vanwago.net/2015/07/25/jumping-the-fold/</id>
    <published>2015-07-25T21:08:36.000Z</published>
    <updated>2018-05-08T17:28:54.326Z</updated>
    
    <content type="html"><![CDATA[<p>Imagine if the three dimensional universe we observe actually was all folded up through a fourth spacial dimension, like a paper all wadded up. While another galaxy might be unfathomably far from us traveling in the three normal dimensions, it could be a short trip across this extra dimension our universe is bent up through.</p><hr><p>My eyes were closed in an expression that probably looked like a wince.</p><p>“First time, kid?” asked the pilot in front of me.</p><p>I nodded without opening my eyes.</p><p>“You alright back there?”</p><p>I nodded again.</p><p>“I can’t see you back there, so you’re gonna need to give me a verbal.”</p><p>I opened my eyes. The tandem seats in this diminutive ship made me claustrophobic in addition to being anxious about the jump.</p><p>“I’m as ready as I’ll ever be,” I replied.</p><p>“Good,” laughed the pilot. “The fold should be right here in front of us. We are jumping on my mark. 3… 2… 1… mark.”</p><p>The stars blinked out in the distance. I expected some sensation of force, but there was none. I felt nothing.</p><p>Consciously I slowed my breath to calm my uneasy nerves, but the pounding in my chest only got louder.</p><p>I could still see the pilot in the dim light cast by the ship’s controls, but outside was complete darkness.</p><p>After a minute or two, the silence broke.</p><p>“Almost there,” said the pilot.</p><p>So our comms work in the fold.</p><p>“Just hang in there another few seconds,” she continued. “Done.”</p><p>As if flipping a switch, stars suddenly blinked back into view, but they were not the stars I saw only a moment ago.</p><p>The pilot tried awkwardly to twist around to look at me. “How was it?” she asked.</p><p>I hesitated to answer, so she offered a response for me. “Rather uneventful, huh?”</p><p>“Yeah,” I replied, “I was expecting a little more something.”</p><p>She laughed as if they all say that. “Welcome to fold jumping. You just traveled about a hundred meters in a direction we don’t have a word for yet, and landed two and a half million light years from where you started. Pretty cool, eh?”</p><p>No response came to mind. I just stared blankly at her.</p><p>After a moment, she rolled her eyes (I think; It’s hard to tell through her helmet) and she turned back to the main console.</p><p>“The station will take about an hour to reach from here through normal space, so I’ll get us going. You just collect your thoughts and let me know when you’re ready to talk.”</p><p>I nodded. She waited a minute.</p><p>“Verbal acknowledgment, please.”</p><p>“Okay,” I said.</p><p>“Thank you.”</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;Imagine if the three dimensional universe we observe actually was all folded up through a fourth spacial dimension, like a paper all wadd</summary>
      
    
    
    
    <category term="Prose" scheme="https://andy.vanwago.net/categories/prose/"/>
    
    
    <category term="Short Story" scheme="https://andy.vanwago.net/tags/short-story/"/>
    
    <category term="Science Fiction" scheme="https://andy.vanwago.net/tags/science-fiction/"/>
    
  </entry>
  
  <entry>
    <title>Breathless in a New World</title>
    <link href="https://andy.vanwago.net/2015/06/23/breathless-in-a-new-world/"/>
    <id>https://andy.vanwago.net/2015/06/23/breathless-in-a-new-world/</id>
    <published>2015-06-24T02:03:10.000Z</published>
    <updated>2018-05-08T17:28:54.322Z</updated>
    
    <content type="html"><![CDATA[<p>Last night I was thinking about the E3 coverage of the upcoming game <a href="http://www.no-mans-sky.com" target="_blank" rel="noopener">No Man’s Sky</a>, as well as the worlds of <a href="http://www.metroid.com/" target="_blank" rel="noopener">Metroid</a>. The following is definitely influenced by forementioned, but it isn’t meant to fit in either as fan fiction. It’s simply an attempt to capture how I imagine being alone on a foriegn world might feel. Especially if something else wanted to claim it first. You never know what is out there.</p><hr><p>No air. I desperately gulped at the void around my face, but I found nothing. Can’t think. Can’t breath. No air.</p><p>My captor unsealed the mask, and a hint of breath filled my starving lungs. Then again, it was sucked out and I was left gasping in vain.</p><p>The room tumbled about me, and the single light blinded me from everything else.</p><p>My insides lurched and the mask filled with bile. Again the mask was removed, and I collapsed on the ground. The bindings on my wrist tore into my flesh through the sudden fall. I barely noticed. I wheezed in the breath of life.</p><p>“We’re going to try this again,” rasped my reptilian captor. “Who else knows about this world?”</p><p>I shook my head with closed eyes.</p><p>The sudden force of a boot pressed every molecule of oxygen from my breast.</p><p>“Final question,” it calmly continued. “After I have suffocated you in your own vomit, into which star shall I send your remains?”</p><p>A weapons I couldn’t recognize rested against my head. In that moment I knew I could close my eyes forever. The searing pain in my chest and head would disappear. An accidental smile stole across my lips.</p><p>“You worthless filth, you.” it sneered, feathers frilling out around its head.</p><p>“I sent … a beacon,” I whispered, between shallow breaths.</p><p>“What did you say?” roared the creature, lifting me up to its face.</p><p>I tried to chuckle, but it turned into more of a cough. I took a solid breath and repeated, “I sent a beacon. It’s only a matter of time now.”</p><p>In disgust, my captor tossed me aside. In a moment I was alone, and the room was silent. Yet I waited. Rather, I rested, and tried to recouperate from near suffocation and being kicked by a being five times my mass.</p><p>The bite of the binding started to sting as my head cleared, so I got up and wandered to where my gear had been discarded. I took no time in locating my blade.</p><p>Once my arms were free, I made my way out of the makeshift shack, and trekked back to the starship. It was unharmed.<br>The data records synced to my ship’s main computer the instant I boarded, and a summary presented itself on the screen.</p><blockquote><p>Stage 3 inhabitable planet<br>Single-cell colonization only<br>Massive deposits of fuel-ready organic mass<br>Massive deposits of a variety of metals</p></blockquote><p>“Send report beacon?” the terminal prompted.</p><p>I accepted. <em>I wouldn’t want to be a liar, now would I?</em></p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;Last night I was thinking about the E3 coverage of the upcoming game &lt;a href=&quot;http://www.no-mans-sky.com&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;</summary>
      
    
    
    
    <category term="Prose" scheme="https://andy.vanwago.net/categories/prose/"/>
    
    
    <category term="Short Story" scheme="https://andy.vanwago.net/tags/short-story/"/>
    
    <category term="Science Fiction" scheme="https://andy.vanwago.net/tags/science-fiction/"/>
    
  </entry>
  
  <entry>
    <title>Async Functions: Delivering on Promises</title>
    <link href="https://andy.vanwago.net/2015/05/11/async-functions-delivering-on-promises/"/>
    <id>https://andy.vanwago.net/2015/05/11/async-functions-delivering-on-promises/</id>
    <published>2015-05-11T18:57:29.000Z</published>
    <updated>2018-05-08T17:28:54.322Z</updated>
    
    <content type="html"><![CDATA[<p>Since Promises were first introduced to JavaScript, I have been frustrated by disappearing errors. Due to its dynamic nature, errors in JavaScript can show up much later in the dev process, sometimes making it all the way to production environments before they are first noticed. Many tools, like linters and type checkers, have been introduced to try to detect errors earlier. However, with Promises sometimes no error is ever thrown at all, your code just doesn’t work as you expect it to.</p><p>A small example to illustrate:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getResult</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function"><span class="keyword">function</span>(<span class="params">resolve, reject</span>) </span>&#123;</span><br><span class="line">    someAsyncFunction(resolve) <span class="comment">// this function may throw an error asynchronously</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>As you can see, <code>reject</code> never gets called. You must explicitly handle the error condition, or you won’t get so much as an error in the console. The error is thrown, but swallowed by the promise.</p><p>So why don’t I just handle the error? The point is not that errors cannot be handled. They certainly can be. The problem is that it is easier to do the wrong thing with promises. By default errors are caught and ignored.</p><p>Furthermore, async stack traces suck. This is a pain point for both promises and callbacks. Assuming an error occurs somewhere deep in asynchrony, the stack may only show you where the error was thrown, and have little or no context of where the function was called in the first place.</p><p><strong>Both of these problems go away when using async function with await.</strong></p><p>ES7 (or ES 2016 if you prefer) proposes a new keywords <code>async</code> and <code>await</code>. Under the hood, the new mechanism uses promises, but by default does the right thing.</p><p>The prior example becomes:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">getResult</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">await</span> someAsyncFunction()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>This code assumes <code>someAsyncFunction</code> is also updated to the new syntax.</p><p>So what did we get?</p><ol><li>If something goes wrong an error is thrown, and ends up in the console if not handled.</li><li>The stack trace is complete, so you can see what initiated the failed action.</li><li>A try/catch around your <code>getResult()</code> call works.</li></ol><p>Want to know more about how <code>async</code> and <code>await</code> work? You can read Jake Archibald gush over their many virtues <a href="http://jakearchibald.com/2014/es7-async-functions/" target="_blank" rel="noopener">on his blog</a>, or if you like, you can check out the surprisingly readable <a href="https://github.com/lukehoban/ecmascript-asyncawait" target="_blank" rel="noopener">proposal</a>.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;Since Promises were first introduced to JavaScript, I have been frustrated by disappearing errors. Due to its dynamic nature, errors in J</summary>
      
    
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/categories/javascript/"/>
    
    
    <category term="ES 2016" scheme="https://andy.vanwago.net/tags/es-2016/"/>
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/tags/javascript/"/>
    
  </entry>
  
  <entry>
    <title>Greater than the sum of its components</title>
    <link href="https://andy.vanwago.net/2013/02/19/greater-than-the-sum-of-its-components/"/>
    <id>https://andy.vanwago.net/2013/02/19/greater-than-the-sum-of-its-components/</id>
    <published>2013-02-20T00:36:43.000Z</published>
    <updated>2018-05-08T17:28:54.324Z</updated>
    
    <content type="html"><![CDATA[<p>Lately I’ve been working on a cool project written exclusively in JavaScript, with a <a href="http://nodejs.org/" target="_blank" rel="noopener">Node.js</a> &amp; <a href="http://www.mongodb.org/" target="_blank" rel="noopener">MongoDB</a> back end, and a <a href="http://thetalecrafter.github.com/modules/" target="_blank" rel="noopener">CommonJS</a> <a href="http://backbonejs.org/" target="_blank" rel="noopener">Backbone</a> front end. What I have found most fun so far is the synergy I get between certain components.</p><p><strong>Templates</strong></p><p>First off, I admit I’m a reinvent-the-wheel kind of engineer. I readily find some minor fault in existing solutions and decide I have to write my own. <a href="https://github.com/visionmedia/ejs" target="_blank" rel="noopener">EJS</a> is really great, especially for someone coming from a PHP background, who doesn’t think logic-less templates are better than sliced bread. However, I really needed templates that can run asynchronously, doing file or network io for includes and other such magic.</p><p>So, I made <a href="http://thetalecrafter.github.com/stencil/" target="_blank" rel="noopener">Stencil</a>. I was able to make templates that compile without mucking up the line numbers, so debugging is very straight-forward. No exception rethrowing necessary. The very-important async use case was satisfied without making all templates forced to use the async pattern.</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sync_result = sync_tpl(data); <span class="comment">// works if no async code in template</span></span><br><span class="line">async_tpl(data, <span class="function"><span class="keyword">function</span>(<span class="params">err, async_result</span>) </span>&#123; &#125;); <span class="comment">// always works</span></span><br></pre></td></tr></table></figure><p>Where the whole becomes more than the sum of parts: A small snippet makes it so I can directly <code>require</code> my templates, and get back the function instead of the string:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">require</span>.extensions[<span class="string">'.html'</span>] = <span class="function"><span class="keyword">function</span>(<span class="params">module, filename</span>) </span>&#123;</span><br><span class="line"><span class="keyword">var</span> fs = <span class="built_in">require</span>(<span class="string">'fs'</span>), stencil = <span class="built_in">require</span>(<span class="string">'stencil-js'</span>),</span><br><span class="line">opts = &#123; <span class="attr">id</span>:filename, <span class="attr">src</span>:fs.readFileSync(filename, <span class="string">'utf8'</span>) &#125;;</span><br><span class="line"><span class="built_in">module</span>._compile(</span><br><span class="line"><span class="string">'module.exports='</span> + stencil.compile(opts, <span class="literal">true</span>) + <span class="string">';'</span>,</span><br><span class="line">filename</span><br><span class="line">);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure><p>Now the rest of my code that uses templates doesn’t have to care that I use Stencil. You just <code>tpl = require(&#39;path/to/template.html&#39;)</code>. This is possible because Node.js has an extensible require, and Stencil allows you to compile to a JavaScript string instead of just to a function. If I were to go back and change the templating system to EJS, Jade, or Mustache, I would only need to update this one little snippet.</p><p><strong>Client CommonJS</strong></p><p>I liked Node.js’s module system, and I didn’t want to have to <a href="http://requirejs.org/docs/node.html" target="_blank" rel="noopener">replace it</a> or use a separate system on the front end. Don’t get me started on mess of <a href="https://github.com/umdjs/umd" target="_blank" rel="noopener">UMD</a>. So, I created my own <a href="http://thetalecrafter.github.com/modules/" target="_blank" rel="noopener">Modules library</a>. You’ve <a href="http://thetalecrafter.com/2010/01/30/javascript-require-in-100-lines-of-code/" title="JavaScript require in 100 lines of code" target="_blank" rel="noopener">heard</a> <a href="http://thetalecrafter.com/2011/04/13/load-only-when-needed-or-preload-everything/" title="Load only when needed, or Preload everything?" target="_blank" rel="noopener">about</a> this <a href="http://thetalecrafter.com/2011/09/22/commonjs-in-the-browser/" title="CommonJS in the Browser" target="_blank" rel="noopener">before</a>.</p><p>I got CommonJS modules to load (asynchronously) and run in the browser, so it was trivial to share code used on both ends. Again, line numbers weren’t munged in the server-side translation, so debugging works just like you always expect it to.</p><p>The library runs as a middleware for <a href="http://expressjs.com/" target="_blank" rel="noopener">Express</a>, enabling the reload functionality <a href="https://github.com/amdjs/amdjs-api/wiki/AMD" target="_blank" rel="noopener">AMD</a> lovers rave about, as well as standalone for concatenating and minifying bundles in the production build process. All with a client-side weight one-third that of <a href="https://github.com/jrburke/almond" target="_blank" rel="noopener">AlmondJS</a>, although that or <a href="http://requirejs.org/" target="_blank" rel="noopener">RequireJS</a> would also work on the front-end, since Modules still uses AMD as its transport format.</p><p>The real magic though, is that the Modules library has an option for translating certain types of files, giving us the same <code>require</code> functionality for our templates that we had on the server, and because the translation happens server side (or at build time), the client code can keep a <a href="http://www.html5rocks.com/en/tutorials/security/content-security-policy/" target="_blank" rel="noopener">Content Security Policy</a> that disallows eval and unsafe inline code, as Stencil never has to be loaded in client code. (Lighter &amp; more secure. Woohoo!)</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">app.use(<span class="built_in">require</span>(<span class="string">'modules'</span>).middleware(&#123;</span><br><span class="line">translate:&#123;</span><br><span class="line">html:<span class="function"><span class="keyword">function</span> <span class="title">tpl</span>(<span class="params">name, file, src</span>) </span>&#123;</span><br><span class="line"><span class="keyword">var</span> opts = &#123; <span class="attr">id</span>:name, <span class="attr">src</span>:src &#125;;</span><br><span class="line"><span class="keyword">return</span> <span class="string">'module.exports='</span> + stencil.compile(opts, <span class="literal">true</span>) + <span class="string">';'</span>;</span><br><span class="line">&#125;</span><br><span class="line">&#125;,</span><br><span class="line">root: <span class="string">'./components/'</span>, <span class="comment">// file root path</span></span><br><span class="line">path: <span class="string">'/module/'</span>, <span class="comment">// url root path</span></span><br><span class="line"><span class="comment">// ... other options</span></span><br><span class="line">&#125;));</span><br></pre></td></tr></table></figure><p><strong>Backbone</strong></p><p>One magic thing that I got for free, is that Backbone and Underscore are already CommonJS compatible, so passing them through the same middleware just worked. <a href="https://github.com/caolan/async" target="_blank" rel="noopener">Async</a>, and countless other Node.js modules also just work.</p><p><strong>Adding it all together</strong></p><p>While I chose to write my own templating and module components, many other libraries include the little hooks that make these synergies possible. Each component individually is really nothing spectacular, but when you put them all together you get a product that is cohesive from front to back, and really fun to work on.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;Lately I’ve been working on a cool project written exclusively in JavaScript, with a &lt;a href=&quot;http://nodejs.org/&quot; target=&quot;_blank&quot; rel=&quot;no</summary>
      
    
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/categories/javascript/"/>
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/tags/javascript/"/>
    
    <category term="CommonJS" scheme="https://andy.vanwago.net/tags/commonjs/"/>
    
    <category term="require" scheme="https://andy.vanwago.net/tags/require/"/>
    
    <category term="AMD" scheme="https://andy.vanwago.net/tags/amd/"/>
    
    <category term="Node.js" scheme="https://andy.vanwago.net/tags/node-js/"/>
    
  </entry>
  
  <entry>
    <title>A Case Against Vendor Prefixes In CSS</title>
    <link href="https://andy.vanwago.net/2012/02/14/a-case-against-vendor-prefixes-in-css/"/>
    <id>https://andy.vanwago.net/2012/02/14/a-case-against-vendor-prefixes-in-css/</id>
    <published>2012-02-14T20:11:04.000Z</published>
    <updated>2018-05-08T17:28:54.321Z</updated>
    
    <content type="html"><![CDATA[<p>I am a web developer, and a rather impatient one too. When a new feature is available in a few browsers, I want to use it. Most of the time, these features are either experimental or not finished with the standardization process when they are generally available. So, they are prefixed by the vendor. This is how the process was designed, so that is what vendors do.</p><p><strong>Why do we prefix?</strong></p><p>Prefixing is a kind of disclaimer for the feature. “Hey this is likely going to change, so don’t rely on it.” This seems in theory like a good way to go about it. If I am a browser maker, and I think of a cool new feature, like say, a gradient defined in css instead of an image, I really won’t know how good my design is until lots of people have used it and given feedback. Of course, if I am conscientious of the community and betterment of the web for everybody, I share my idea with other browser vendors and get their take on it too. Often we have competing ideas of how to implement it, so we want a way to distinguish between them. This competition is wonderful, and will lead us to a better solution. So, I make my background-image:-andy-linear-gradient(…), and my competitor makes their background:-steve-gradient(linear, color-stop(), …). Some people can try it out and it will work through the standards process and eventually everyone will have a background:linear-gradient(…) feature.</p><p>In theory it works out great, but what about in practice?</p><p><strong>Here’s what actually happens, from a dev’s perspective.</strong></p><p>My favorite browser, Shiny, implements a cool new feature: -shiny-gradient(). I play with it and think it’s really cool, but to be safe, I don’t actually use it in any production site. A year later, the other browser I support, Ice Monster has long since added their own -ice-gradient(). Two years later, pretty much every browser has their own prefixed version, even the Laggard browser.</p><p>Nice. It only took two years for the feature to be generally available, so I start to use it, even though my code looks like this:</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">background-image</span>: <span class="selector-tag">-shiny-gradient</span>(<span class="selector-tag">linear</span>, <span class="selector-tag">left</span> <span class="selector-tag">top</span>, <span class="selector-tag">left</span> <span class="selector-tag">bottom</span>, <span class="selector-tag">from</span>(<span class="selector-tag">hsl</span>(0, 80%, 70%)), <span class="selector-tag">to</span>(<span class="selector-id">#BADA55</span>));</span><br><span class="line"><span class="selector-tag">background-image</span>: <span class="selector-tag">-shiny-linear-gradient</span>(<span class="selector-tag">top</span>, <span class="selector-tag">hsl</span>(0, 80%, 70%), <span class="selector-id">#BADA55</span>);</span><br><span class="line"><span class="selector-tag">background-image</span>:    <span class="selector-tag">-ice-linear-gradient</span>(<span class="selector-tag">top</span>, <span class="selector-tag">hsl</span>(0, 80%, 70%), <span class="selector-id">#BADA55</span>);</span><br><span class="line"><span class="selector-tag">background-image</span>:    <span class="selector-tag">-lag-linear-gradient</span>(<span class="selector-tag">top</span>, <span class="selector-tag">hsl</span>(0, 80%, 70%), <span class="selector-id">#BADA55</span>);</span><br><span class="line"><span class="selector-tag">background-image</span>:     <span class="selector-tag">-my-linear-gradient</span>(<span class="selector-tag">top</span>, <span class="selector-tag">hsl</span>(0, 80%, 70%), <span class="selector-id">#BADA55</span>);</span><br><span class="line"><span class="selector-tag">background-image</span>:         <span class="selector-tag">linear-gradient</span>(<span class="selector-tag">top</span> <span class="selector-tag">bottom</span>, <span class="selector-tag">hsl</span>(0, 80%, 70%), <span class="selector-id">#BADA55</span>);</span><br></pre></td></tr></table></figure><p>I don’t mind too much, because I use SASS or some other css pre-processor that actually takes care of all the prefixes and nuances. But this still bothers me in two important ways.</p><ol><li>My stylesheets are getting much heavier than they used to be, which is a concern because I want people to be able to view my site quickly even on mobile devices. Most of the syntax is exactly the same, but I still have to write it over and over again for each vendor.</li><li>I have to opt in for each browser I want to get the feature. If a new browser becomes popular, it won’t get the gradients unless I go back and add yet another version.<br>I complain, but I keep doing it anyway. Two years later (Now <strong>four years</strong> since it was first introduced), The standard is still a draft, and because I want to support not just the bleeding edge browser, even when the standard finalizes I must leave all of the vendor prefixes indefinitely.</li></ol><p><strong>The problem gets more real with mobile.</strong></p><p>Management asks for a ShinyPhone version of our application. They don’t care about Robot, even though it uses -shiny prefixes. I am given enough time to make the ShinyPhone version, but no time to even test in Robot. Eventually though, I manage to get it working because I own a Robot phone.</p><p>A few months later, Catchup Phone 7, Ice Monster Mobile, and Concert Mini are showing up on more phones. They have their prefixed version of all the great Shiny features I used, but because I didn’t know about them, the mobile application looks awful, and would take me several weeks to fix for each new phone. Management is not willing to spend that kind of time, so <strong>even though they have all the features my site is broken for them</strong>. Who will our customers blame? It works on ShinyPhone, so it must be that Ice Monster Mobile just isn’t as good. <strong>Ice Monster and other browsers get blamed for my site not working well there</strong>.</p><p><strong>The Solution?</strong></p><p>It is clear that if other browsers want to make themselves look good, they have to do more than just implement the feature. <strong>If they just use -shiny prefixes</strong>, that would make my application work far better, and therefore make their browser look good. But that completely undermines what we’ve learned in the browser wars, and goes against the reason for prefixing in the first place!</p><p><strong>We don’t really have a good solution yet.</strong></p><p>However, I have an idea I think worth talking about. <strong>What if the feature hadn’t been prefixed at all?</strong> I would have been less nervous to put it into production, because CSS simply doesn’t apply rules that aren’t implemented, and though it will likely change syntax, I can add new versions, and the one that is implemented will work. My stylesheet ends up more like this:</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">background-image</span>: <span class="selector-tag">gradient</span>(<span class="selector-tag">linear</span>, <span class="selector-tag">left</span> <span class="selector-tag">top</span>, <span class="selector-tag">left</span> <span class="selector-tag">bottom</span>, <span class="selector-tag">from</span>(<span class="selector-tag">hsl</span>(0, 80%, 70%)), <span class="selector-tag">to</span>(<span class="selector-id">#BADA55</span>));</span><br><span class="line"><span class="selector-tag">background-image</span>: <span class="selector-tag">linear-gradient</span>(<span class="selector-tag">top</span> <span class="selector-tag">bottom</span>, <span class="selector-tag">hsl</span>(0, 80%, 70%), <span class="selector-id">#BADA55</span>);</span><br></pre></td></tr></table></figure><p>My application just works for every browser that supports the feature with little thought or effort from my part, and if the spec doesn’t change, which it actually doesn’t change very often, I am already done more than four years before it is standardized.</p><p><strong>Benefits of prefixing:</strong></p><ol><li><strong>Sense</strong> of security for browser vendors, so they can change the implementation and make it better.</li><li>Web developers <strong>should</strong> be aware that the feature isn’t really ready yet.</li><li><p><strong>Credit</strong> goes to the vendor who pioneered the feature.<br><strong>Benefits of NOT prefixing:</strong></p></li><li><p><strong>Less effort</strong> and maintenance for web developers trying to make their application (and browsers) look good. They don’t need to spend a lot of time researching which browsers support which features.</p></li><li><strong>Lighter weight</strong> stylesheets for everyone, especially mobile browsers.</li><li>Browser vendors can focus on the <strong>feature</strong>s, not on evangelizing their prefix.</li><li><strong>No -webkit- prefixes being supported by Mozilla</strong>. Dang, I said it after trying so hard not to.<br>Honestly I do see the value in prefixing experimental and non-standardized features, but vendors have to break them often, and the standard needs to move faster if developers are realistically going to experiment with experimental features, and wait for the standard for production use.</li></ol><p>Please feel free to disagree in the comments, check out the discussion going on in the <a href="http://lists.w3.org/Archives/Public/www-style/2012Feb/0313.html" target="_blank" rel="noopener">w3c</a>, or <a href="http://paulirish.com/2012/vendor-prefixes-are-not-developer-friendly/" target="_blank" rel="noopener">read up</a> on <a href="http://blog.vandenoostende.com/2012/on-vendor-prefixes/" target="_blank" rel="noopener">other</a> <a href="http://www.sitepoint.com/w3c-css-webkit-prefix-crisis/" target="_blank" rel="noopener">opinions</a>. Better yet, <a href="http://www.change.org/petitions/microsoft-mozilla-opera-dont-make-webkit-prefixes-a-de-facto-standard" target="_blank" rel="noopener">get involved</a>.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;I am a web developer, and a rather impatient one too. When a new feature is available in a few browsers, I want to use it. Most of the ti</summary>
      
    
    
    
    <category term="CSS" scheme="https://andy.vanwago.net/categories/css/"/>
    
    
    <category term="browser" scheme="https://andy.vanwago.net/tags/browser/"/>
    
    <category term="css" scheme="https://andy.vanwago.net/tags/css/"/>
    
    <category term="moz" scheme="https://andy.vanwago.net/tags/moz/"/>
    
    <category term="ms" scheme="https://andy.vanwago.net/tags/ms/"/>
    
    <category term="prefix" scheme="https://andy.vanwago.net/tags/prefix/"/>
    
    <category term="web" scheme="https://andy.vanwago.net/tags/web/"/>
    
    <category term="webkit" scheme="https://andy.vanwago.net/tags/webkit/"/>
    
  </entry>
  
  <entry>
    <title>On Pattern Hating</title>
    <link href="https://andy.vanwago.net/2011/10/07/on-pattern-hating/"/>
    <id>https://andy.vanwago.net/2011/10/07/on-pattern-hating/</id>
    <published>2011-10-08T04:50:21.000Z</published>
    <updated>2018-05-08T17:28:54.326Z</updated>
    
    <content type="html"><![CDATA[<p>I have long considered myself a Java hater. I now think it really has nothing to do with the language itself. Sure it was easy to point at slow performance (hasn’t been true for a long time now), or mourn for missing syntactic sugar (Pattern.compile(‘abc’, Pattern.CASE_INSENSITIVE) vs /abc/i), but really I think my problem with Java is really just a problem with the mindset I have observed in novice programmers (with Java usually being their first language).</p><p><strong>The problem is with patterns.</strong></p><p>Patterns are great. They provide a toolbox that can lead developers on the road to “best practice”. But…</p><p><strong>Patterns are a poor substitute for problem solving.</strong></p><p>It doesn’t matter if you know how to make a Singleton, even if you know when a Singleton is useful, if the problem at hand is improving report speed. You need to know math, you need to know computation, and you need to find the unnecessary work being done. It’s possible we’ll use a Singleton, but it won’t be the solution to the problem.</p><p>In an interview, if I ask for code to find the most common words in a bunch of text files, “public class WordRanker {“ is unimportant. I’ve seen a few programmers struggle for the first few minutes to figure out if it should be a class, a function, or what language to use. But once, I was impressed by someone who quickly figured out what they wanted to do, and then said, “I’d google how to do that.”</p><p>The pattern is accidental complexity. Problem solving is essential complexity.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;I have long considered myself a Java hater. I now think it really has nothing to do with the language itself. Sure it was easy to point a</summary>
      
    
    
    
    <category term="General" scheme="https://andy.vanwago.net/categories/general/"/>
    
    
    <category term="Java" scheme="https://andy.vanwago.net/tags/java/"/>
    
    <category term="patterns" scheme="https://andy.vanwago.net/tags/patterns/"/>
    
    <category term="problem solving" scheme="https://andy.vanwago.net/tags/problem-solving/"/>
    
  </entry>
  
  <entry>
    <title>CommonJS in the Browser</title>
    <link href="https://andy.vanwago.net/2011/09/22/commonjs-in-the-browser/"/>
    <id>https://andy.vanwago.net/2011/09/22/commonjs-in-the-browser/</id>
    <published>2011-09-22T20:33:25.000Z</published>
    <updated>2018-05-08T17:28:54.323Z</updated>
    
    <content type="html"><![CDATA[<p>I’ve been thinking a lot lately about how to use <a href="http://wiki.commonjs.org/wiki/Modules/1.1.1" target="_blank" rel="noopener">CommonJS modules</a> in my web applications. I even started a <a href="https://github.com/thetalecrafter/modules" target="_blank" rel="noopener">repository on github</a> for my implementation. As is apparent from <a href="http://lmgtfy.com/?q=commonjs+in+the+browser" target="_blank" rel="noopener">searching</a>, the task is non-trivial, and there are lots of people trying to do the same thing, and every one of them has a different idea about how it should work.</p><p><strong>But WHY would you want to use CommonJS (formerly known as ServerJS) modules in a client environment?</strong></p><p>Ideally you can share modules between client and server, but that requires you to use a server environment like <a href="nodejs.org">node.js</a>, which might make management really nervous. Even without sharing the CommonJS module system helps us avoid some annoyances in JavaScript development.</p><ul><li>Each module has it’s own scope. I don’t have to manually wrap each file in a function to get a new variable scope. (Of course, to achieve this, the boilerplate is going to have to wrap each module’s code in a function anyway.)</li><li>Namespaces are only used in the require function, not everywhere in my code. Almost inevitably every web application I’ve worked in ends up using code like the following:<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> whatIWanted = <span class="keyword">new</span> FormerCompanyName.Common.CoolLibrary.ConstructorName( More.namespace.chains.than.you.can.follow );</span><br><span class="line"><span class="comment">// the rest of this file continues to use these ridiculously long namespaces</span></span><br></pre></td></tr></table></figure></li></ul><p>Although I’m sure many will disagree with me, I much prefer the CommonJS way:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> CoolModule = <span class="built_in">require</span>(<span class="string">'common/cool-library'</span>),</span><br><span class="line">    thingINeed = <span class="built_in">require</span>(<span class="string">'more/namespace/chains/than/you/can/follow'</span>),</span><br><span class="line">    whatIWanted = <span class="keyword">new</span> CoolModule.ConstructorName(thingINeed);</span><br><span class="line"><span class="comment">// the rest of the file is void of long namespaces</span></span><br></pre></td></tr></table></figure><p>And much more importantly, when I define a new module (or class as some insist on calling them):</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">FormerCompanyName.Common.CoolLibrary.ConstructorName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="comment">/* ... */</span>&#125;;</span><br><span class="line"><span class="comment">// versus</span></span><br><span class="line">exports.ConstructorName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="comment">/* ... */</span>&#125;;</span><br><span class="line"><span class="comment">// or even</span></span><br><span class="line"><span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="comment">/* ... */</span>&#125; <span class="comment">// this case isn't in the spec, but I really like it, so I made sure my library can handle it.</span></span><br></pre></td></tr></table></figure><ul><li>Because you can also use relative module identifiers (“./sibling-module”, “../uncle-module”), when the company changes it’s name, it can be as simple as renaming a folder to update all the top-level module ids.</li><li>Additionally, modules can be included in the page in any order, and are only executed when first required, instead of all modules executing immediately upon inclusion, requiring the script order to be specific and fragile. If I add a new module using CommonJS, I can just append it to the end of the list, otherwise I have to make sure it is earlier in the page than whatever uses it, and after whatever it uses.<br><strong>Okay, but how much work is it going to be?</strong></li></ul><p>Let’s walk through first what I wanted my server-side code to look like, then what it has to do to make it work on the other side.</p><p>As most of my server-side experience thus far has been in php, that’s the first language I’ve used in my implementation.</p><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;title&gt;My Awesome Application&lt;/title&gt;</span><br><span class="line">    &lt;link rel=<span class="string">"stylesheet"</span> href=<span class="string">"awesome-styles.css"</span> /&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">    &lt;!-- blah blah blah --&gt;</span><br><span class="line">    <span class="meta">&lt;?</span>= Modules::script() <span class="comment">/* include all necessary script tags */</span> <span class="meta">?&gt;</span></span><br><span class="line">    &lt;script&gt;<span class="keyword">require</span>(<span class="string">'awesome'</span>).go()&lt;/script&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure><p>The Modules class will look for all js files in the folder you put it in, and any subfolders, and will id them by their path.</p><p>Yes, I am including every module, not actually checking dependencies. I refer you back to <a href="/2011/04/13/load-only-when-needed-or-preload-everything/">my previous post</a> and say this is the simplest way, and if the caching headers are working, the experience won’t suffer. You are welcome to use one of the <a href="http://lmgtfy.com/?q=async+require+javascript" target="_blank" rel="noopener">fantastic libraries</a> that loads modules on-demand, if you disagree.</p><p>Hopefully that is all the server-side API you need to worry about, but there is more if you need it.</p><p><strong>So what is that library doing to my poor scripts to make the CommonJS module environment?</strong></p><p>I will explain in detail what goes into it in another post, but if you are daring, you can check out the source on <a href="https://github.com/thetalecrafter/modules" target="_blank" rel="noopener">github</a>.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;I’ve been thinking a lot lately about how to use &lt;a href=&quot;http://wiki.commonjs.org/wiki/Modules/1.1.1&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Com</summary>
      
    
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/categories/javascript/"/>
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/tags/javascript/"/>
    
    <category term="CommonJS" scheme="https://andy.vanwago.net/tags/commonjs/"/>
    
    <category term="include" scheme="https://andy.vanwago.net/tags/include/"/>
    
    <category term="modules" scheme="https://andy.vanwago.net/tags/modules/"/>
    
    <category term="require" scheme="https://andy.vanwago.net/tags/require/"/>
    
  </entry>
  
  <entry>
    <title>Some thoughts on Web 4.0</title>
    <link href="https://andy.vanwago.net/2011/04/16/some-thoughts-on-web-4-0/"/>
    <id>https://andy.vanwago.net/2011/04/16/some-thoughts-on-web-4-0/</id>
    <published>2011-04-16T13:57:57.000Z</published>
    <updated>2018-05-08T17:28:54.327Z</updated>
    
    <content type="html"><![CDATA[<p>The web has undergone some significant changes since its inception. 1.0 consisted mostly of HTML documents, with simple CSS style, and little or no JavaScript interaction. 2.0 was the AJAX revolution, making dynamic sites with complex JavaScript. Some have suggested we are already in 3.0, with HTML5 and SVG well supported in the latest version of every major browser. What I’d like to talk about, is what I wish would come next.</p><p>As many who are immersed in front-end web development have noticed, HTML and SVG have different DOMs, different styles, and competing animation tools. They have been getting better, with HTML5’s inline SVG support, and browsers beginning to bring each markup’s features to the other, but the inconsistencies are still painful, and and they make implementation both for web and browser developers sub-optimal.</p><p>What I would love to see is something akin to the following document:<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>Fancy HTML+SVG<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">href</span>=<span class="string">"styles.css"</span> /&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">defs</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">path</span> <span class="attr">id</span>=<span class="string">"logo"</span> <span class="attr">desc</span>=<span class="string">"My Fancy SVG Logo"</span> <span class="attr">d</span>=<span class="string">"M59,0 l69,69 h-15 l-44,44 v15 l-69-69 h15 l45-45 5,5 -45,45 44,44 44-44 -49-49 z  M59,44 c0-8,10-8,10,0 v40 c0,8-10,8-10,0 z"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">filter</span> <span class="attr">id</span>=<span class="string">"soft_blur"</span>&gt;</span><span class="tag">&lt;<span class="name">feGaussianBlur</span> <span class="attr">in</span>=<span class="string">"SourceGraphic"</span> <span class="attr">stdDeviation</span>=<span class="string">".5"</span>/&gt;</span><span class="tag">&lt;/<span class="name">filter</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">defs</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"shortcut icon"</span> <span class="attr">sizes</span>=<span class="string">"16x16 24x24 32x32 48x48"</span> <span class="attr">href</span>=<span class="string">"#logo"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">header</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">a</span> <span class="attr">id</span>=<span class="string">"home"</span> <span class="attr">href</span>=<span class="string">"."</span>&gt;</span><span class="tag">&lt;<span class="name">use</span> <span class="attr">href</span>=<span class="string">"#logo"</span> /&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h1</span>&gt;</span>The TaleCrafter&amp;#039;s Scribbles<span class="tag">&lt;<span class="name">h1</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h2</span>&gt;</span>notes about science, fiction, and faith… but mostly web development<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">header</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">article</span>&gt;</span>My Article text and images and stuff go here<span class="tag">&lt;/<span class="name">article</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">footer</span>&gt;</span>Boring Legal and maybe locale selection in here<span class="tag">&lt;/<span class="name">footer</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"script.js"</span> <span class="attr">async</span> <span class="attr">defer</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></p><p>styles.css<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#logo</span> &#123; <span class="attribute">background</span>:<span class="number">#111</span>; &#125; <span class="comment">/* applies to everywhere &lt;use&gt;d, including favicon */</span></span><br><span class="line"><span class="selector-id">#home</span> &#123; <span class="attribute">width</span>:<span class="number">64px</span>; <span class="attribute">height</span>:<span class="number">64px</span>; <span class="attribute">float</span>:left; &#125;</span><br><span class="line"><span class="selector-id">#home</span> <span class="selector-tag">path</span> &#123; <span class="attribute">transform</span>:<span class="built_in">scale</span>(.5); <span class="attribute">transition</span>:background .<span class="number">5s</span> ease; &#125;</span><br><span class="line"><span class="selector-id">#home</span> <span class="selector-tag">path</span><span class="selector-pseudo">:hover</span> &#123; <span class="attribute">background</span>:<span class="number">#0d0dc5</span>; &#125;</span><br><span class="line"><span class="selector-tag">h1</span> &#123; <span class="attribute">filter</span>:<span class="built_in">url</span>(#soft_blur); <span class="attribute">transition</span>:filter .<span class="number">5s</span> linear; &#125;</span><br><span class="line"><span class="selector-tag">h1</span><span class="selector-pseudo">:hover</span> &#123; <span class="attribute">filter</span>:none; &#125;</span><br><span class="line"><span class="comment">/* ... lots more styles ... */</span></span><br></pre></td></tr></table></figure></p><p>script.js<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">document</span>.querySelector(<span class="string">'#home path'</span>).addEventListener(<span class="string">'click'</span>, <span class="comment">/* open menu or something useful */</span>);</span><br></pre></td></tr></table></figure></p><p>Summary of things that would be cool:</p><ul><li>no need for foreignObject or anything like that, simply mix and match tags</li><li>put all the useful attributes in the same namespace (make use is useful without xlink: namespace)</li><li>css transitions &amp; animations on svg styles (properties would also be nice)</li><li>defs and use in html documents</li><li>filters on html elements (Firefox is already working on this)</li><li>unify styles like background and fill</li><li>JavaScript DOM API identical<br>In short SVG and HTML would be one and the same. You would style both with the same css.</li></ul><p>Some nitpicks:</p><ul><li>I’m not sold on defining filters in markup, then using in style. It feels… odd. Why not define in style? (Oh no, that might be too much like IE’s filters! Gasp!)</li><li>Animating is still a crapshoot. It feels like it should be in JavaScript, but declarative syntax is so much simpler, and easier to optimize for browsers. Some SMIL animations work in some browsers. CSS animations are still nacent but promising. (Even IE looks like it might implement it in ‘native HTML5’. Sorry, couldn’t help myself.) Still, JavaScript is the only reliable way right now.</li></ul><p>Let me hear an Amen, or let me know what I’m missing. Leave a comment and let’s talk about it.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;The web has undergone some significant changes since its inception. 1.0 consisted mostly of HTML documents, with simple CSS style, and li</summary>
      
    
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/categories/javascript/"/>
    
    
    <category term="ajax" scheme="https://andy.vanwago.net/tags/ajax/"/>
    
    <category term="html5" scheme="https://andy.vanwago.net/tags/html5/"/>
    
    <category term="svg" scheme="https://andy.vanwago.net/tags/svg/"/>
    
  </entry>
  
  <entry>
    <title>Load only when needed, or Preload everything?</title>
    <link href="https://andy.vanwago.net/2011/04/13/load-only-when-needed-or-preload-everything/"/>
    <id>https://andy.vanwago.net/2011/04/13/load-only-when-needed-or-preload-everything/</id>
    <published>2011-04-13T18:47:07.000Z</published>
    <updated>2018-05-08T17:28:54.326Z</updated>
    
    <content type="html"><![CDATA[<p>As JavaScript and web application best practices have formed over the last several years, there have appeared two contesting patterns in loading the scripts needed for an application:</p><p><strong>Don’t load any JavaScript until you know you need it.</strong></p><p>I usually feel like this is the way to go, because a lot of my code is specific to a particular widget or workflow. Why make the page take longer to load initially for something the user won’t do every visit? Just put in minimal stubs to load the full functionality once the user begins down that workflow, or interacts with the widget.</p><p>Pros:</p><ul><li>Lighter initial page weight</li><li>Encourages functionally modular code</li><li>Memory performance boost (important if you have to support old browsers)</li><li>Speed performance boost (if done right)</li></ul><p>Cons:</p><ul><li>Adds additional complexity to code</li><li>Laggy performance (if done wrong)</li><li>Lots of HTTP requests</li></ul><p><strong>Combine and minify all JavaScript into one file loaded at the end of the html file.</strong></p><p>You know beforehand what is going to be needed on each page, and YSlow warned you about too many HTTP requests. Bundle up all the scripts into one download which will be cached after the first page view.</p><p>Pros:</p><ul><li>Easy to implement (lots of code will do it for you)</li><li>Initial page load (once cached) is really fast</li></ul><p>Cons:</p><ul><li>Load a lot more than usually necessary</li><li>Initial load can be much slower</li></ul><p>So how do you know which pattern to follow? It depends! If your application is very complex, and large portions of the functionality are used infrequently, it makes a lot of sense to use an on-demand pattern. If your application is fairly simple, or if all of the code is likely to be used every time, then combining all of the scripts and including it from the start will be much easier.</p><p>I recently worked on a smaller application where I divided all the script into two files. The first was loaded initially, and provided enough functionality for the login dialog only. Upon successful login, the second script was loaded, which combined all of the remaining pieces of application.</p><p>The point I most want to make is this: <strong>Don’t just follow a pattern because it is a “best practice”.</strong> Take the time to figure out the best solution for your project.</p>]]></content>
    
    
      
      
    <summary type="html">&lt;p&gt;As JavaScript and web application best practices have formed over the last several years, there have appeared two contesting patterns in </summary>
      
    
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/categories/javascript/"/>
    
    
    <category term="JavaScript" scheme="https://andy.vanwago.net/tags/javascript/"/>
    
    <category term="require" scheme="https://andy.vanwago.net/tags/require/"/>
    
    <category term="script" scheme="https://andy.vanwago.net/tags/script/"/>
    
    <category term="ajax" scheme="https://andy.vanwago.net/tags/ajax/"/>
    
    <category term="minify" scheme="https://andy.vanwago.net/tags/minify/"/>
    
  </entry>
  
</feed>
