<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="">
  <title>Blog Title</title>
  <subtitle>This is a longer description about your blog.</subtitle>
  <link href="https://example.com/atom.xml" rel="self" />
  <link href="https://example.com/" />
  <updated>2026-01-19T00:00:00Z</updated>
  <id>https://example.com/</id>
  <author>
    <name>Your Name</name>
  </author>
  <entry>
    <title>IOS Web Service</title>
    <link href="https://example.com/blog/ios-web-service.html" />
    <updated>2012-08-08T00:00:00Z</updated>
    <id>https://example.com/blog/ios-web-service.html</id>
    <content type="html">&lt;p&gt;This following example is a small snippet of code I found to call a simple web service and return it to a NSURL string. You will need to use a XML parser to parse your web services data. This web service sends the request information in the url.&lt;/p&gt;
&lt;pre class=&quot;language-clike&quot;&gt;&lt;code class=&quot;language-clike&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;BOOL&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;CallService&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;NSString &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;value
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Call web service to verify a session object or string&lt;/span&gt;
    BOOL result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; YES&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// Create the objects for calling the web service&lt;/span&gt;
    NSString &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;buildURL &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSString stringWithFormat&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;@&lt;span class=&quot;token string&quot;&gt;&quot;https://coryrylan.com/web-services/MyWebServices.asmx/myServiceCheck?IDReceived=%@&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; ID&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    NSURL &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;url &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSURL URLWithString&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;buildURL&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;//Call the request&lt;/span&gt;
    NSURLRequest &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;urlRequest &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSURLRequest requestWithURL&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;url&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	cachePolicy&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;NSURLRequestReturnCacheDataElseLoad
    timeoutInterval&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// Create the objects for parsing the xml data returned by web service&lt;/span&gt;
    NSData &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    NSURLResponse &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    NSError &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;error&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// Call the web service&lt;/span&gt;
    xmlData &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSURLConnection sendSynchronousRequest&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;urlRequest returningResponse&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;response error&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;error&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    NSXMLParser &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;parser &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSXMLParser alloc&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; initWithData&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;parser setDelegate&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;self&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// You can create a parser method to remove any whitespaces or apending chars if needed&lt;/span&gt;

    reply &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSMutableString alloc&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;init&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// Read the xml data returned by the web service&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;parser parse&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;reply isEqualToString&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;@&lt;span class=&quot;token string&quot;&gt;&quot;yourErrorResponse&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;//If your service returned ect do this&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        ErrorMessage &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; @&lt;span class=&quot;token string&quot;&gt;&quot;Error&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; NO&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;reply isEqualToString&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;@&lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; reply &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; NULL&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Else if no reply do that, or use error object&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;//No reply from web service&lt;/span&gt;
        ErrorMessage &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; @&lt;span class=&quot;token string&quot;&gt;&quot;Connection Error&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; NO&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; result&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;token comment&quot;&gt;//Else return the result or error&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;//XML PARSER&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;NSString&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;parser&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;NSXMLParser &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;parser foundCharacters&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;NSString &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;string
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    reply &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSString stringWithString&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;string&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; reply&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>IOS Journey Load Animation</title>
    <link href="https://example.com/blog/ios-load-animation.html" />
    <updated>2012-08-20T00:00:00Z</updated>
    <id>https://example.com/blog/ios-load-animation.html</id>
    <content type="html">&lt;p&gt;This following example is a small snippet of code to create a small loading animation for your IOS apps in Objective C.&lt;/p&gt;
&lt;pre class=&quot;language-clike&quot;&gt;&lt;code class=&quot;language-clike&quot;&gt;UIActivityIndicatorView &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;loadAnimation &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;UIActivityIndicatorView alloc&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

initWithActivityIndicatorStyle&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;UIActivityIndicatorViewStyleGray&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

loadAnimation&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;center &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CGPointMake&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;160&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;220&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

loadAnimation&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;hidesWhenStopped &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; YES&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;self&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;view addSubview&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;loadAnimation&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;loadAnimation startAnimating&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>IOS Journey Load Multi-Threading</title>
    <link href="https://example.com/blog/ios-multi-threading.html" />
    <updated>2012-08-20T00:00:00Z</updated>
    <id>https://example.com/blog/ios-multi-threading.html</id>
    <content type="html">&lt;p&gt;This following example is a small snippet of code I found to create a separate thread from the main thread. This allows you to process information without holding the main thread. For example if a web service is taking a while to load or respond if on the main thread the application may shut down because it believes the application has locked up. This allows the user interface to be usable while loading.&lt;/p&gt;
&lt;pre class=&quot;language-clike&quot;&gt;&lt;code class=&quot;language-clike&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// For asynchronous threading use the following and place code within brackets.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;dispatch_async&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dispatch_get_global_queue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;DISPATCH_QUEUE_PRIORITY_DEFAULT&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;unsigned long&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;NULL&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;void&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Example Thread separate until view loaded then push&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;self&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;navigationController pushViewController&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;myViewController animated&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;YES&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// For a separate thread place your method call in the following selector.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSThread detachNewThreadSelector&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; @&lt;span class=&quot;token function&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;MyMethod&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; toTarget&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;self
withObject&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;nil&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// To break out of the current thread and process something on the main use the following:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;self performSelectorOnMainThread&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;@&lt;span class=&quot;token function&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;yourMethod&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; withObject&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;nil waitUntilDone&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;YES&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>IOS Journey the Observer</title>
    <link href="https://example.com/blog/ios-observer.html" />
    <updated>2012-08-20T00:00:00Z</updated>
    <id>https://example.com/blog/ios-observer.html</id>
    <content type="html">&lt;p&gt;The NSNotification observer allows you to add a observer which watches for a certain event to trigger. This is useful if a view come into the display or the app is resumed from being suspended in the background. This example is setting an observer to the &lt;code&gt;UIApplicationDidBecomeActiveNotification&lt;/code&gt;. When this event occurs the selector of the method of your choosing will fire. This is useful if the app has been suspended and need to update its information via web service.&lt;/p&gt;
&lt;pre class=&quot;language-clike&quot;&gt;&lt;code class=&quot;language-clike&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSNotificationCenter defaultCenter&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; addObserver&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;self
    selector&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;@&lt;span class=&quot;token function&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;someMethod&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        name&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;UIApplicationDidBecomeActiveNotification object&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;nil&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>IOS Character Counter</title>
    <link href="https://example.com/blog/ios-character-counter.html" />
    <updated>2012-08-23T00:00:00Z</updated>
    <id>https://example.com/blog/ios-character-counter.html</id>
    <content type="html">&lt;p&gt;This following example is a small character counter that can keep track of the number of characters in a text view that needs to be limited to a maximum amount of characters.&lt;/p&gt;
&lt;pre class=&quot;language-clike&quot;&gt;&lt;code class=&quot;language-clike&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;//Only check if text field has been altered&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;void&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;textViewDidChange&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;UITextView &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;textView&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;//500 chars max&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;textView text&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; length&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;//If max reached close keypad&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;textView resignFirstResponder&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;//Append off extra chars&lt;/span&gt;
        textView&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;text &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;textView&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;text substringToIndex&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;//Count and display amount of chars left&lt;/span&gt;
    CounterBoxLabel&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;text &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;NSString stringWithFormat&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;@&lt;span class=&quot;token string&quot;&gt;&quot;Characters left: (%i)&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;textView text&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; length&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Javascript JQuery Ajax</title>
    <link href="https://example.com/blog/javascript-ajax.html" />
    <updated>2012-08-29T00:00:00Z</updated>
    <id>https://example.com/blog/javascript-ajax.html</id>
    <content type="html">&lt;p&gt;This following example is a small snippet of code for a AJAX web service call to&lt;br&gt;
a .NET service with JQuery. We will be sending a email and name to our web service to sign up for a email subscription.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*JS Email Subscription AJAX web service*/&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;callService&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;callService&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Here we will create our data object to send. In this example we are&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// sending a email subscription request. We will send a email address and a name.&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; data &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;#emailTextBox&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;#nameTextBox&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;val&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  $&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ajax&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;POST&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;/myWebServices.asmx/emailSubscription&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; data &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;contentType&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;application/json; charset=utf-8&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;dataType&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;json&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;d &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;You have been subscribed&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;//Do any work you want if the web service was successful.&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Error&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;//Or throw a error&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;error&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;//Or throw a error if service failed&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Agile Development Is Not Bad</title>
    <link href="https://example.com/blog/agile-development-is-not-bad.html" />
    <updated>2013-03-19T00:00:00Z</updated>
    <id>https://example.com/blog/agile-development-is-not-bad.html</id>
    <content type="html">&lt;p&gt;I often hear proponents to agile code say that it makes sloppy untested code.&lt;br&gt;
I feel that this is incorrect and should be addressed. The idea of rapid deployment and agile code development is simplify how we think, write, and source control our code. By breaking our code into smaller iterations they become more maintainable and easier to deploy.&lt;/p&gt;
&lt;p&gt;Code proves whether a theory works or not. Trying to make all the features for a product or making them perfect only delays your releases and puts strain on your team. By making your features small and easy to release you also make them easier to test. Would you rather test a small feature set and release or a large milestone with many features? We should be testing as we go but often a large milestone is pushed to production then the team is inundated for weeks with bug or feature fixes. If we would keep the milestones small and light we can fixes problems as we ship and keep our products shipping without halting our development cycle.&lt;/p&gt;
&lt;p&gt;By rapid deployment we can get immediate feedback from our customers and users. Nothing is more detrimental on the morale of a team than to spend months on a feature only to find out that the customer does not like or use it. This could of been prevented by releasing a small simple version of your feature. It does one thing and one thing well. We would of gotten feedback about the core idea of our feature much sooner and save many resources doing so.&lt;/p&gt;
&lt;p&gt;Agile code comes down to one thing. Simple. Simple feature, simple idea, easier tests. The core idea is retained. The product or feature is in its most simple state it becomes easier to test and maintain. So in summary, keep it simple, keep it short, test early and often with users. Deploy, receive feedback, correct, and repeat. Following this cycle will help you keep your code clean and maintainable while getting your product out there.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Emotional Interfaces</title>
    <link href="https://example.com/blog/emotional-interfaces.html" />
    <updated>2013-03-19T00:00:00Z</updated>
    <id>https://example.com/blog/emotional-interfaces.html</id>
    <content type="html">&lt;p&gt;As web developers and designers it’s our responsibility that our users have the best experience possible. This may seem like obvious advice but is often ignored or put on the back burner on larger scale projects. The interface is what the user initially responds to. It’s comparable to a first impression. If our interface fails to convey our message or have a good impression we have lost our user before they have even used our product.&lt;/p&gt;
&lt;p&gt;Our interfaces cannot lie. Interfaces must reach a human connection conveying our intent clearly. This usually is the case for any good design. But to convey our message clearly we must be careful with our context and content. Our context is what gives our interface the human element. Think about any emails or text messages you have received in the past. How often did you read the message in one tone or context to find out later that was not the true meaning or intent of the message? Was the tone meant to be more serious? Was it lighthearted and fun? This often happens with our users. The tone and context of our interface can distort our true intent we want for the user.&lt;/p&gt;
&lt;p&gt;How we design must be intertwined with our context, content, and emotion. This can help guide the user without glaring messages or instructions. It should feel natural as if it were a human to human conversation. They understand your tone and intent immediately, this helps the user become comfortable with your interface. If you can accomplish this your users will return and enjoy their experience every time.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The Performance Advocate</title>
    <link href="https://example.com/blog/the-performance-advocate.html" />
    <updated>2013-03-19T00:00:00Z</updated>
    <id>https://example.com/blog/the-performance-advocate.html</id>
    <content type="html">&lt;p&gt;I wanted to write this after working on a large mobile first responsive redesign. Our project goal was to redesign a static desktop site to become a clean fast responsive website to allow all devices to access our website.&lt;/p&gt;
&lt;p&gt;Often our design process was interrupted will feature implementation and last minute changes. A feature or design was added in all good intent but was never questioned about how this could effect the site performance. Note to clarify I will refer site performance to front end performance and not server side performance. Most of your site speed will be on client side based on load, render, and script performances.&lt;/p&gt;
&lt;p&gt;We had multiple developers implementing multiple featured and page modifications. Front end performance may not be your teams strong suit but should always be top priority in you implementations. Not everyone knows the pitfalls with client browsers. To resolve this teams should always have a Performance Advocate. This person should always question performance with any design or feature implementation. Even if the idea seems solid, question it. Test it on multiple devices and networks. Find the pitfalls and issues that could arise. Your Performance Advocate could commonly fall under the job title as a Front End Engineer or Front End Dev Ops, etc.&lt;/p&gt;
&lt;p&gt;The Performance Advocate should focus on these three main issues with every decision:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Render Performance ( Perceived Load Time / Jank )&lt;/li&gt;
&lt;li&gt;Page Load Weight&lt;/li&gt;
&lt;li&gt;Script Performance&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There should be strict performance standards in projects and the Performance&lt;br&gt;
Advocate should help enforce these standards. These standards could be the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Maximum Page load with no cache will not exceed 500kb anything else will be deferred&lt;/li&gt;
&lt;li&gt;All Javascript will be deferred after onload&lt;/li&gt;
&lt;li&gt;No inline JS&lt;/li&gt;
&lt;li&gt;CSS should never be more than 3 selectors deep or exceed 30kb total&lt;/li&gt;
&lt;li&gt;All static resources are minified and Gzipped into single files on a CDN&lt;/li&gt;
&lt;li&gt;Our maximum onload requests is 5 everything else is deferred.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are just a handful of example standards the team should establish.&lt;br&gt;
Define them in the beginning of the project. They should become part of code reviews and testing. Project performance standards should never get in the way of emergency bug fixes. Performance guidelines should be at the project level. Some projects may require more lenient or strict rules. The advocate should check these standards with every feature. If the feature breaks a rule then the team must meet to determine how the feature can be implemented while meeting the guidelines. Without the advocate the end result could be a slow product. If the advocate challenges this before code is even touched we can keep the performance in the design from the beginning creating a fluid and fast application.&lt;/p&gt;
&lt;p&gt;For features or systems already in place that did not meet the standards the development team should set time or budget to fix these issues. The advocate or anyone should submit issues, pull request or cases to fix the issues. Make it aware that your team is delivering a sub par product by not fixing these problems. The idea of the performance advocate is NOT that only one person should worry about performance, the ENTIRE TEAM should always focus on performance. The advocate is a assigned role to ensure and enforce the performance standards of the project.&lt;/p&gt;
&lt;br&gt;
The breakdown
&lt;br&gt;
Design &gt; Question &gt; Implement &gt; Test &gt; Reflect
&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;Design your feature or application&lt;/li&gt;
&lt;li&gt;Question the performance issues and address the issues&lt;/li&gt;
&lt;li&gt;Implement the code and correct any performance issues&lt;/li&gt;
&lt;li&gt;Test, test your audience, mobile, low end devices, mobile networks, etc.&lt;/li&gt;
&lt;li&gt;Reflect, did we meet the budgets and performance guidelines? If not back to the drawing board to come up with improvements.&lt;/li&gt;
&lt;/ol&gt;
</content>
  </entry>
  <entry>
    <title>Thoughts On Large Mobile First Responsive Project</title>
    <link href="https://example.com/blog/thoughts-on-large-mobile-first-responsive-project.html" />
    <updated>2013-11-11T00:00:00Z</updated>
    <id>https://example.com/blog/thoughts-on-large-mobile-first-responsive-project.html</id>
    <content type="html">&lt;p&gt;These are just some of my thoughts after working on a large mobile first responsive design project. These are some key points or highlights that I feel were most important in the project construction.&lt;/p&gt;
&lt;h2 id=&quot;design&quot; tabindex=&quot;-1&quot;&gt;Design &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/thoughts-on-large-mobile-first-responsive-project.html#design&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Ensure a designer or dev with design experience designs features not devs or clients to prevent poor typography and missing design fundamentals&lt;/li&gt;
&lt;li&gt;Include front end engineers with the design aspects to be an advocate for performance but able to contribute to the design&lt;/li&gt;
&lt;li&gt;Wire frame the html and css mobile first then upwards defining your breakpoints&lt;/li&gt;
&lt;li&gt;Build all html and css then pass on to backend dev team to hook up to sever, allows clean markup and eliminated repetitive styles&lt;/li&gt;
&lt;li&gt;Have style guide created with html and css before project begins.&lt;/li&gt;
&lt;li&gt;Do not allow client to make last minute design changes, causes rendering bugs to be introduced unexpectedly&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;styles&quot; tabindex=&quot;-1&quot;&gt;Styles &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/thoughts-on-large-mobile-first-responsive-project.html#styles&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use SASS, helps keep your code DRY&lt;/li&gt;
&lt;li&gt;Only 1 to 2 people on Styles ( CSS, SASS, LESS) ( issues will duplicate styles and poor render performance ) or Module out your application between designers&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;implementation&quot; tabindex=&quot;-1&quot;&gt;Implementation &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/thoughts-on-large-mobile-first-responsive-project.html#implementation&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Design mobile first and performance first&lt;/li&gt;
&lt;li&gt;Have a Performance Advocate&lt;/li&gt;
&lt;li&gt;Set performance rules and guidelines and follow thoroughly&lt;/li&gt;
&lt;li&gt;Set support guidelines such as minimum browser requirements for your application&lt;/li&gt;
&lt;li&gt;Be very cautious of browser sniffing as it add code complexity and can bite you later ( Bad sniff ). Feature detection is always better.&lt;/li&gt;
&lt;li&gt;Ensure that your server side framework compliments your front end code and does not work against it. If so then change it.&lt;/li&gt;
&lt;li&gt;Use progressive enhancement to build site resilience to failure such as lack of features or graceful degradation.&lt;/li&gt;
&lt;li&gt;Have no Javascript fall-backs for at least key features. Not just for no js users but for network resilience such as js failed to load because of weak mobile network.&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>2014 Blog Update</title>
    <link href="https://example.com/blog/2014-new-year-update.html" />
    <updated>2014-01-05T00:00:00Z</updated>
    <id>https://example.com/blog/2014-new-year-update.html</id>
    <content type="html">&lt;p&gt;So its been a great year for me as a student and part time web developer. I was able to work in a great responsive web site &lt;a href=&quot;https://www.estatesales.net&quot;&gt;EstateSales.NET&lt;/a&gt; and learned much from it. Now that its 2014 I will graduate in the spring and I have officially been hired as a full time web developer at &lt;a href=&quot;https://www.vintagesoftware.com&quot;&gt;Vintage Software&lt;/a&gt;. Excited to start new projects this year. This year I will be focusing on some new topics.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Web performance on responsive web sites.&lt;/li&gt;
&lt;li&gt;Maintainable responsive design&lt;/li&gt;
&lt;li&gt;Resilient web design&lt;/li&gt;
&lt;li&gt;Off-line support on web applications&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Look for me on &lt;a href=&quot;https://github.com/coryrylan&quot;&gt;Github&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://codepen.io/coryrylan&quot;&gt;codepen.io&lt;/a&gt; for any new projects or want to collaborate just&lt;br&gt;
tweet me &lt;a href=&quot;https://twitter.com/coryrylan&quot;&gt;@coryrylan&lt;/a&gt; Happy new year!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Web Con, University of Illinois Conference Notes Part 1.</title>
    <link href="https://example.com/blog/web-con-2014-notes-part1.html" />
    <updated>2014-05-01T00:00:00Z</updated>
    <id>https://example.com/blog/web-con-2014-notes-part1.html</id>
    <content type="html">&lt;p&gt;Here are my notes from University of Illinois Web Con 2014. These are from the talk&lt;br&gt;
&lt;a href=&quot;http://innovatorylife.com/2014/05/02/life-without-a-bs-foundation/&quot;&gt;&amp;quot;Life without a BS Foundation&amp;quot;&lt;/a&gt;&lt;br&gt;
by &lt;a href=&quot;https://twitter.com/kianoshp&quot;&gt;Kianosh Pourian&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&quot;Build a framework around your design not design around your framework.&quot;
&lt;/blockquote&gt;
&lt;p&gt;Cons for using front end frameworks such as Twitter Bootstrap and Zurb Foundation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Not semantic&lt;/li&gt;
&lt;li&gt;Naming conventions not established/documented poorly&lt;/li&gt;
&lt;li&gt;Performance issues (bloat)&lt;/li&gt;
&lt;li&gt;Little to no file structure especially Sass project for Bootstrap&lt;/li&gt;
&lt;li&gt;Difficult to update&lt;/li&gt;
&lt;li&gt;Design implementation frameworks fall short&lt;/li&gt;
&lt;li&gt;Does not follow the DRY principals&lt;/li&gt;
&lt;li&gt;Overriding is very difficult and tons of extra code and uses little of the framework&lt;/li&gt;
&lt;li&gt;Editing the framework breaks any update&lt;/li&gt;
&lt;li&gt;Impossible to create a framework for everyone&lt;/li&gt;
&lt;li&gt;CSS is old and part of the issue&lt;/li&gt;
&lt;li&gt;Spend a lot of time learning someone else&#39;s code&lt;/li&gt;
&lt;li&gt;Not ideal for enterprise or large applications&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&quot;When building a site or web application, one must build it for success. Success means that small projects will evolve into large projects.
&lt;/blockquote&gt;
&lt;p&gt;What to do:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;quot;Do the sh*t yourself&amp;quot;&lt;/li&gt;
&lt;li&gt;Write your own CSS&lt;/li&gt;
&lt;li&gt;Create Style Guides&lt;/li&gt;
&lt;li&gt;Use Sass or a preprocessor&lt;/li&gt;
&lt;li&gt;Follow OOCSS Principals&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://bradfrostweb.com/blog/post/atomic-web-design/&quot;&gt;Atomic Design&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Organize your code in modules in folders (each folder is a atom or module)&lt;/li&gt;
&lt;li&gt;The global import file should have comment of what the modules are being imported for&lt;/li&gt;
&lt;li&gt;Have a unified naming convention&lt;/li&gt;
&lt;li&gt;Folders helps packages modules for individual consumption&lt;/li&gt;
&lt;li&gt;Learn from frameworks such as Twitter Bootstrap and Zurb Foundation&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Web Con, University of Illinois Conference Notes Part 2.</title>
    <link href="https://example.com/blog/web-con-2014-notes-part2.html" />
    <updated>2014-05-01T00:00:00Z</updated>
    <id>https://example.com/blog/web-con-2014-notes-part2.html</id>
    <content type="html">&lt;p&gt;Here are my notes from University of Illinois Web Con 2014. These are from the talk&lt;br&gt;
&amp;quot;Learn Every Programming Language&amp;quot; by &lt;a href=&quot;https://twitter.com/PatrickDelancy&quot;&gt;Patrick Delancy&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4 programming paradigms&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Procedural&lt;/li&gt;
&lt;li&gt;Logical&lt;/li&gt;
&lt;li&gt;Functional&lt;/li&gt;
&lt;li&gt;Object Oriented&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Procedural&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Loops&lt;/li&gt;
&lt;li&gt;Procedures/Functions/Subroutines&lt;/li&gt;
&lt;li&gt;Global/Static Variables&lt;/li&gt;
&lt;li&gt;GoTo&lt;/li&gt;
&lt;li&gt;Lexical Scoping&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Object Oriented&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Class/Entity&lt;/li&gt;
&lt;li&gt;Abstraction (interfaces)&lt;/li&gt;
&lt;li&gt;Encapsulation&lt;/li&gt;
&lt;li&gt;Inheritance&lt;/li&gt;
&lt;li&gt;Polymorphism&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Functional&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Focuses on the process and not the entity models&lt;/li&gt;
&lt;li&gt;Functions as values&lt;/li&gt;
&lt;li&gt;Pattern Matching&lt;/li&gt;
&lt;li&gt;Composition&lt;/li&gt;
&lt;li&gt;Partial Application&lt;/li&gt;
&lt;li&gt;Monad/Computation Expression&lt;/li&gt;
&lt;li&gt;Closures (JavaScript and C#)&lt;/li&gt;
&lt;li&gt;Deconstruction/Decomposition&lt;/li&gt;
&lt;li&gt;Currying (JavaScript)&lt;/li&gt;
&lt;li&gt;Recursion/Tail Recursion&lt;/li&gt;
&lt;li&gt;Option/Maybe&lt;/li&gt;
&lt;li&gt;cons/car/cdr&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Logical&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Facts&lt;/li&gt;
&lt;li&gt;Relationships&lt;/li&gt;
&lt;li&gt;Very declarative&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Site Performance Review 8/2014</title>
    <link href="https://example.com/blog/site-performance-review-08-2014.html" />
    <updated>2014-08-01T00:00:00Z</updated>
    <id>https://example.com/blog/site-performance-review-08-2014.html</id>
    <content type="html">&lt;p&gt;So I decided to take a performance review of my own personal site after some optimization work and write about some of my findings. I did a average content breakdown on my home page and will cover a few other pages that load different resources.&lt;/p&gt;
&lt;p&gt;I calculated all the resources for first time view on my home page with gzip. I do not include third party resources such as Google Analytics and Disqus because they are usually async and are outside of the developers control.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;Content Breakdown for coryrylan.com (home page gzipped)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Resource&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Size&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Percentage&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;HTML&lt;/th&gt;
            &lt;td&gt;2.5kb&lt;/td&gt;
            &lt;td&gt;2.9%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;CSS&lt;/th&gt;
            &lt;td&gt;7.5kb&lt;/td&gt;
            &lt;td&gt;9.0%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;JavaScript&lt;/th&gt;
            &lt;td&gt;0kb&lt;/td&gt;
            &lt;td&gt;0%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Images&lt;/th&gt;
            &lt;td&gt;17.8kb&lt;/td&gt;
            &lt;td&gt;20.9%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;SVG&lt;/th&gt;
            &lt;td&gt;23.2kb&lt;/td&gt;
            &lt;td&gt;27.4%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Fonts&lt;/th&gt;
            &lt;td&gt;33.6kb&lt;/td&gt;
            &lt;td&gt;39.8%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Total&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;84.6kb&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;javascript&quot; tabindex=&quot;-1&quot;&gt;JavaScript &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014.html#javascript&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If you closely you will notice I have 0kb of JavaScript. Excluding Google Analytics this is correct. I have other JavaScript dependencies on my site I load only when needed. I use Disqus for blog comments. I also use Prism.js for code examples on my blog as well. On my Contact page I use JQuery &amp;amp; JQuery Unobtrusive Validation library for my contact form validation. Listed below is the content breakdown of all JavaScript resources on my site.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;JavaScript Breakdown (gzipped)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Resource&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Size&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Percentage&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;JQuery &amp;amp; Validation (Contact)&lt;/th&gt;
            &lt;td&gt;46.6kb&lt;/td&gt;
            &lt;td&gt;90.1%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Prism.js (Blog)&lt;/th&gt;
            &lt;td&gt;5.1kb&lt;/td&gt;
            &lt;td&gt;9.9%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Total&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;51.7kb&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;css&quot; tabindex=&quot;-1&quot;&gt;CSS &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014.html#css&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I only have one CSS file that is minified. I use Sass as a preprocessor for my CSS. I generate a separate CSS file for ie8 non media query support.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;CSS Breakdown (9.0% gzipped)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Selectors&lt;/th&gt;
            &lt;td&gt;695&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Rules&lt;/th&gt;
            &lt;td&gt;382&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Total&lt;/th&gt;
            &lt;td&gt;7.5kb&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Performance side note, because my CSS is so small I can inline this in the head of the document to get a faster paint time. This is because the server will not need to go get a CSS file to start rendering the screen. I have tried this and it does improve speed but I have not yet found a build process that I am happy with to automate this.&lt;/p&gt;
&lt;h2 id=&quot;html&quot; tabindex=&quot;-1&quot;&gt;HTML &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014.html#html&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I have one HTML page requested from a prerendered view on the server. I do not&lt;br&gt;
pull any dynamic content except on blog post comments.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;HTML Breakdown (2.9% gzipped)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Resource&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Size&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Percentage&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Home Page&lt;/th&gt;
            &lt;td&gt;2.5kb&lt;/td&gt;
            &lt;td&gt;100%&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;images&quot; tabindex=&quot;-1&quot;&gt;Images &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014.html#images&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I have two images on my home page currently. I have one JPG and one SVG background. I do have images&lt;br&gt;
on other pages of my site such as blog posts. All my images are compressed and gzipped.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;Images Breakdown (48.3% gzipped)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Resource&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Size&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Percentage&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Image of myself&lt;/th&gt;
            &lt;td&gt;17.8kb&lt;/td&gt;
            &lt;td&gt;43.5%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Background SVG (gzip fails)&lt;/th&gt;
            &lt;td&gt;23.1kb&lt;/td&gt;
            &lt;td&gt;56.5%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Total&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;40.9kb&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;svg&quot; tabindex=&quot;-1&quot;&gt;SVG &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014.html#svg&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Performance side note, currently SVG images are not gzipping on my Azure host and I am working on a solution. This causes a extra ~15kb to be downloaded. If anyone knows of a solution please feel free to comment.&lt;/p&gt;
&lt;p&gt;I load in two font sets for my site. The first is Roboto Regular for my base font. The second is a custom built icon set from Fontello.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;Font Breakdown (39.8% gzipped)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;Stat&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Fontello&lt;/th&gt;
            &lt;td&gt;6.5kb&lt;/td&gt;
            &lt;td&gt;19.2%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Roboto Regular&lt;/th&gt;
            &lt;td&gt;27.3kb&lt;/td&gt;
            &lt;td&gt;80.8%&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Size&lt;/th&gt;
            &lt;td&gt;33.8kb&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Performance tests can be skewed because if you request the browser to prefetch/prerender other pages in the background to make them load faster. I turned this off while running the tests. Prerendering doubled my load time because of loading resources for other pages even if the requested page was completely rendered. This skewed my page speed index score. This applied to &lt;a href=&quot;http://www.webpagetest.org/&quot;&gt;webpagetest.org&lt;/a&gt; and not to &lt;a href=&quot;http://developers.google.com/speed/pagespeed/insights/&quot;&gt;Google Page Speed&lt;/a&gt;&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;Performance Stats&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Load time&lt;/th&gt;
            &lt;td&gt;1.689s&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Start Render&lt;/th&gt;
            &lt;td&gt;0.996s&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Speed Index (3G connection)&lt;/th&gt;
            &lt;td&gt;1291&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Google Page Speed Mobile&lt;/th&gt;
            &lt;td&gt;88/100&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Google Page Speed Desktop&lt;/th&gt;
            &lt;td&gt;95/100&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;6 Requests&lt;/th&gt;
            &lt;td&gt;84.6kb&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Overall my site has pretty good performance. My Page Speed Index is around 1291 on a 3g connection. My Google page speed mobile ranks a 88 out of 100 and desktop a 95/100. Good scores but definitely can be improved. My major performance issue currently is my SVG images not gzipping. I am guessing some type of config issue. My other major performance issue is CSS loading. I can optimize my CSS by inlining in the head or deferring the unnecessary parts. I also could defer loading of my web fonts to improve render time and make the site useable sooner. I&#39;ll be post a update after working on some improvements and see how much faster I can push my site.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>SVG gzip in Windows Azure</title>
    <link href="https://example.com/blog/svg-gzip-windows-azure.html" />
    <updated>2014-08-04T00:00:00Z</updated>
    <id>https://example.com/blog/svg-gzip-windows-azure.html</id>
    <content type="html">&lt;p&gt;When running a Windows Azure website you may run into a problem I came across with gzipping content. By default Azure websites are very easy to set up and have little maintenance cost. Most of the performance features are turned on by default with one exception. SVG images seem to not gzip on website instances.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;strike&quot;&gt;Azure Websites seem to also ignore the web config overrides for this as well.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;strike&quot;&gt;
  Unfortunately the way to turn this on is to use Web Roles. I did not want to deal with that hassle so I created a controller to handle incoming SVG requests as recommended from these two posts, [Stack Overflow](http://stackoverflow.com/questions/17029543/enable-gzip-compression-for-svg-in-azure-web-sites) and
  [Asp Weblogs](http://weblogs.asp.net/jongalloway/asp-net-mvc-routing-intercepting-file-requests-like-index-html-and-what-it-teaches-about-how-routing-works).
&lt;/p&gt;
&lt;p&gt;Thanks to David Ebbo (&lt;a href=&quot;https://twitter.com/davidebbo&quot;&gt;@davidebbo&lt;/a&gt;) he pointed me in the right direction in making a better solution. it turns out you can get gzip to turn on for SVG with the web config. The solution is below, as well as the comments.&lt;/p&gt;
&lt;pre class=&quot;language-markup&quot;&gt;&lt;code class=&quot;language-markup&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;configuration&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;system.webServer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;staticContent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
         &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;mimeMap&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;fileExtension&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;.svg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image/svg+xml&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;staticContent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;httpCompression&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
         &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;staticTypes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
           &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;remove&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;*/*&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
           &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;add&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image/svg+xml&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;true&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
           &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;add&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;*/*&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;false&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
         &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;staticTypes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;httpCompression&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;system.webServer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;configuration&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The key part I was previously missing was the &lt;code&gt;&amp;lt;remove mimetype=&amp;quot;*/*&amp;quot; /&amp;gt;&lt;/code&gt;.&lt;br&gt;
If you read the comments by David it seems that this will be fixed and turned on by default on the next Azure update.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>ASP MVC Critical CSS Performance</title>
    <link href="https://example.com/blog/asp-mvc-critical-css-performance.html" />
    <updated>2014-08-06T00:00:00Z</updated>
    <id>https://example.com/blog/asp-mvc-critical-css-performance.html</id>
    <content type="html">&lt;p&gt;I recently did a &lt;a href=&quot;https://example.com/blog/site-performance-review-08-2014&quot;&gt;performance review of my own site&lt;/a&gt; and have added multiple improvements. One of best improvements was optimizing the loading of my critical CSS. By including the critical CSS inlined in the head of the HTML we can send in a single response everything the browser needs to start rendering our view. The browser now does not have to wait on a request to a external stylesheet. Try to keep the total size of the HTML and inlined CSS to around 14kb. This will allow the browser to more likely receive the HTML file altogether and not receive it in multiple portions across the network. This reduces latency and improves the render speed. This is difficult to achieve but is a good goal to shoot for.&lt;/p&gt;
&lt;p&gt;The hard part is determining what is critical to your view as this can change on a page to page basis. My site is fairly simple so I deferred CSS such as animations, web font definitions and print styles as they are not necessary to get the view painted to the screen. There are many tools to help identify your critical CSS. &lt;a href=&quot;https://github.com/giakki/uncss&quot;&gt;UnCSS&lt;/a&gt; and &lt;a href=&quot;https://github.com/addyosmani/grunt-uncss&quot;&gt;Grunt UnCSS&lt;/a&gt; on GitHub are great tools to help automate this process. I am not going to cover these tools in this post, I&#39;ll be focusing on how I was able to get my CSS inlined into my ASP MVC views.&lt;/p&gt;
&lt;p&gt;The first set up I have is I leverage Sass to precompile and organize my CSS in a modular style. I group all my non critical CSS in one CSS generated file. This file I load asynchronously using the Filament Group&#39;s &lt;a href=&quot;https://github.com/filamentgroup/loadCSS&quot;&gt;LoadCSS&lt;/a&gt;. Using this I can defer my CSS until after page load. This example uses the MVC bundling feature with a no js fallback.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;span class=&quot;token language-javascript&quot;&gt;
    &lt;span class=&quot;token comment&quot;&gt;// loadCSS&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;loadCSS&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;t&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;n&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;link&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; o&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;script&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;rel&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;href&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;media&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;onlyx&quot;&lt;/span&gt;o&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;parentNode&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;insertBefore&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;o&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;media&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;n&lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;all&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;loadCSS&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;@Styles.Url(&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;bundles&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;deferred&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;css&lt;span class=&quot;token string&quot;&gt;&quot;)&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;noscript&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    @Styles.Render(&quot;~/bundles/deferred/css&quot;)
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;noscript&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So now that we are deferring our non critical CSS we inline the CSS needed to render what is visible when the HTML loads. I bundle and minify my CSS with Sass for this bundle as well but you could use the MVC bundling tool. Even better use a Grunt/Gulp task to identify exactly what critical CSS the page needs. A side note, any JavaScript in the head should be async so it does not prevent the browser from the critical render path.&lt;/p&gt;
&lt;p&gt;To inline your CSS you can use the following line in your views.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token style&quot;&gt;&lt;span class=&quot;token language-css&quot;&gt;
  &lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@html&lt;/span&gt;.raw &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;File.&lt;span class=&quot;token function&quot;&gt;ReadAllText&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Server.&lt;span class=&quot;token function&quot;&gt;MapPath&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;~/Content/Sass/all.min.css&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a really easy simple way to improve performance on your site if it has a small amount of CSS. If you have a large site with large CSS files I would recommend leveraging a Gulp/Grunt task to identify what CSS should be deferred.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Site Performance Review 8/2014 Part Two</title>
    <link href="https://example.com/blog/site-performance-review-08-2014-part-two.html" />
    <updated>2014-08-11T00:00:00Z</updated>
    <id>https://example.com/blog/site-performance-review-08-2014-part-two.html</id>
    <content type="html">&lt;p&gt;I recently did a &lt;a href=&quot;https://example.com/blog/site-performance-review-08-2014&quot;&gt;performance review of my own site&lt;/a&gt;. In this post I am going to cover what I did to improve my site performance and what challenges there were. Here is my site before I started optimizing my pages.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;Old Performance Stats (Home Page 3G connection)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Load time&lt;/th&gt;
            &lt;td&gt;1.689s&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Start Render&lt;/th&gt;
            &lt;td&gt;0.996s&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Speed Index (3G connection)&lt;/th&gt;
            &lt;td&gt;1291&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Google Page Speed Mobile&lt;/th&gt;
            &lt;td&gt;88/100&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Google Page Speed Desktop&lt;/th&gt;
            &lt;td&gt;95/100&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;6 Requests&lt;/th&gt;
            &lt;td&gt;84.6kb&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;gzip-and-svg&quot; tabindex=&quot;-1&quot;&gt;Gzip and SVG &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014-part-two.html#gzip-and-svg&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;So the first major issue for slowing my site down was my SVG images not gzipping. I load a large background SVG onto the site that was about 23kb. I looked into why my Azure server configuration was not gzipping SVGs and I came up with a solution. Unfortunately this was the most difficult issue to resolve. I wrote a blog post on what I did to fix this here, &lt;a href=&quot;https://example.com/blog/svg-gzip-windows-azure&quot;&gt;SVG gzip Windows Azure&lt;/a&gt;. After resolving this I was able to compress the SVG background down to 7.6kb.&lt;/p&gt;
&lt;h2 id=&quot;fonts&quot; tabindex=&quot;-1&quot;&gt;Fonts &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014-part-two.html#fonts&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The next fix to improve performance was to optimize my fonts. I use Roboto as my font site wide. Loading in a custom web font really slows down the text render time on the page especially on mobile. So the first thing I did was go to &lt;a href=&quot;http://fontsquirrel.com&quot;&gt;fontsquirrel.com&lt;/a&gt; and subset my copy of Roboto. Before sub setting my file size was 23.7kb total. After sub setting I reduced my file down to 17.6kb total.&lt;/p&gt;
&lt;p&gt;Next I deferred loading of my font until after document load. This causes FOUT (flash of unstyled text) but if the web font is lost in the network or slow to load the browser will be using the default system font until the custom web font is loaded. I used the Filament Group&#39;s awesome script &lt;a href=&quot;https://github.com/filamentgroup/loadCSS&quot;&gt;LoadCSS&lt;/a&gt;. Something I noticed is if you use the HTML5 prerender/prefetch feature it can minimize FOUT on the next page. I only noticed this in Chrome.&lt;/p&gt;
&lt;h2 id=&quot;css&quot; tabindex=&quot;-1&quot;&gt;CSS &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014-part-two.html#css&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Deferring your non critical CSS and inlining critical CSS in the head of the document can greatly improve your render times. The idea is if you inline your CSS the document the CSS will arrive with the document and the browser can start rendering your page immediately. The browser does not have to wait to load in a external stylesheet. The tricky park is knowing what to inline and what not to inline. Only inline the minimal amount to render above the fold content. Anything else can wait. The other issue is you need to keep this inline small. You don&#39;t want to bloat your HTML pages with inlined CSS. The ideal amount is to keep your HTML and inlined CSS to a total of 14kb This helps ensure the file is sent altogether. This is a difficult guideline but a good&lt;br&gt;
one to shoot for.&lt;/p&gt;
&lt;p&gt;The CSS I chose to defer were selectors that dealt with animations, font loading, icon fonts, and print styles. All of this CSS was unnecessary to get the first time render to the screen. I used the LoadCSS script to load in me non critical CSS. I wrote a small blog post on how I &lt;a href=&quot;https://example.com/blog/asp-mvc-critical-css-performance&quot;&gt;inlined critical CSS for a MVC project&lt;/a&gt;. I used unCSS to analyze what selectors were not being used and removed unnecessary ones as needed.&lt;/p&gt;
&lt;h2 id=&quot;the-aftermath&quot; tabindex=&quot;-1&quot;&gt;The Aftermath &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/site-performance-review-08-2014-part-two.html#the-aftermath&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Here are my performance test scores now after all of the optimizations.&lt;/p&gt;
&lt;table&gt;
    &lt;caption&gt;New Performance Stats (Home Page 3G Connection)&lt;/caption&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Load time&lt;/th&gt;
            &lt;td&gt;1.3s&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Start Render&lt;/th&gt;
            &lt;td&gt;0.7s&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Speed Index (3G connection)&lt;/th&gt;
            &lt;td&gt;994&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Google Page Speed Mobile&lt;/th&gt;
            &lt;td&gt;98/100&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;Google Page Speed Desktop&lt;/th&gt;
            &lt;td&gt;100/100&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;6 Requests&lt;/th&gt;
            &lt;td&gt;68kb&lt;/td&gt;
            &lt;td&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p&gt;First paint with text to screen in less than 1 second on a good 3G connection. [#perfmatters](https://twitter.com/hashtag/perfmatters?src=hash) [pic.twitter.com/HqNg493Z3O](http://t.co/HqNg493Z3O)&lt;/p&gt;&amp;mdash; Cory Rylan (@coryrylan) [August 2, 2014](https://twitter.com/coryrylan/statuses/495618360089268224)&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;Overall the work was well work it. My site can now render in one second on a good 3G connection and half a second on a cable connection. Optimizing client side performance can be difficult at times but with good tooling it can be a automated process of your builds.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>AngularJS Controller As Syntax</title>
    <link href="https://example.com/blog/angularjs-controller-as-syntax.html" />
    <updated>2014-09-12T00:00:00Z</updated>
    <id>https://example.com/blog/angularjs-controller-as-syntax.html</id>
    <content type="html">&lt;p&gt;Angular JS has some great MVC, MVVM or MVW (Model View Whatever) patterns. In Angular there are a few different ways to declare and use a controller. Lets look at the most common way using the &lt;code&gt;$scope&lt;/code&gt; object.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-app&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-controller&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ScopeExampleCtrl&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    {{message}}
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; angular&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;app&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ScopeExampleCtrl&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;$scope&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  $scope&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;This is a model value from the $scope syntax.&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So this works great no issues but lets look at the &lt;code&gt;Controller As&lt;/code&gt; syntax that was introduced in Angular 1.2&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-app&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-controller&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ControllerAsExampleCtrl as example&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    {{example.message}}
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; angular&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;app&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ControllerAsExampleCtrl&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Value from the &quot;Controller As&quot; syntax.&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This syntax does a few things for us. The first benefit is we don&#39;t need to bring in $scope as a dependency. This cleans up our controller a bit. We can directly add any properties we want on our view by using &lt;code&gt;this&lt;/code&gt; on the controller. You can still bring &lt;code&gt;$scope&lt;/code&gt; in as a dependency if you need to use other things such as &lt;code&gt;$watch&lt;/code&gt; or &lt;code&gt;$on&lt;/code&gt;. This allows you to easily be able to see controllers that may have special exceptions than your average controller.&lt;/p&gt;
&lt;h2 id=&quot;nesting-controllers&quot; tabindex=&quot;-1&quot;&gt;Nesting Controllers &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/angularjs-controller-as-syntax.html#nesting-controllers&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In the view the &lt;code&gt;ControllerAsExampleCtrl as example&lt;/code&gt; the &lt;code&gt;example&lt;/code&gt; creates a instance of the &lt;code&gt;ControllerAsExampleCtrl&lt;/code&gt; for that controller&#39;s view. So lets look at why this is important.&lt;/p&gt;
&lt;p&gt;In the next example we have a simple controller that assigns a string to the scope value of message. We inject the $scope object as a dependency of the controller. So what happens if we nest two controllers that happen to have the same property of message?&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-app&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-controller&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ScopeExampleCtrl1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    {{message}}
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-controller&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ScopeExampleCtrl2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      {{message}}
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; angular&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;app&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ScopeExampleCtrl1&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;$scope&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  $scope&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;$scope value from Controller 1&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ScopeExampleCtrl2&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;$scope&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  $scope&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;$scope value from Controller 2&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you look at the HTML it can quickly become confusing to understand which property belongs to which controller. This is even worse when we have base controllers or large sections of HTML that divide up the controller declarations. Take a look at the same controllers but using &lt;code&gt;Controller As&lt;/code&gt; to bind their values.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-app&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-controller&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ControllerAsVmExampleCtrl1 as example1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    {{example1.message}}
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ng-controller&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ControllerAsVmExampleCtrl2 as example2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      {{example2.message}}
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; angular&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;app&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ControllerAsVmExampleCtrl1&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Controller As value from Controller 1&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ControllerAsVmExampleCtrl2&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Controller As value from Controller 2&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If we use the &lt;code&gt;Controller As&lt;/code&gt; syntax we can avoid this issue. It simplifies the code and makes it clear which property belongs to each controller. This also helps us from not having to use the &lt;code&gt;$parent&lt;/code&gt; property. When you declare with &lt;code&gt;Controller As&lt;/code&gt; we get a single instance of that controller with the name that you define. So we have a instance of &lt;code&gt;ControllerAsVmExampleCtrl1&lt;/code&gt; named &amp;quot;example1,&amp;quot; and a instance of &lt;code&gt;ControllerAsVmExampleCtrl2&lt;/code&gt; named &amp;quot;example2.&amp;quot; This prevents the &lt;code&gt;name&lt;/code&gt; properties from possibly colliding with each other.&lt;/p&gt;
&lt;h2 id=&quot;controller-as-vm&quot; tabindex=&quot;-1&quot;&gt;Controller as VM &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/angularjs-controller-as-syntax.html#controller-as-vm&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Attaching our models using &lt;code&gt;this&lt;/code&gt; on our controllers leads to a clean syntax but what happens when the context of &lt;code&gt;this&lt;/code&gt; changes?&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; angular&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;app&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ControllerAsVmExampleCtrl1&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;$scope&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Hello World&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  $scope&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;$watch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;newVal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newVal&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;undefined&#39;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The issue here is &lt;code&gt;this.message&lt;/code&gt; in our &lt;code&gt;$watch&lt;/code&gt; method now references to the function execution context instead of the &lt;code&gt;this.message&lt;/code&gt; on the controller. To fix this we could use &lt;code&gt;.bind()&lt;/code&gt; This would fix the issue of &lt;code&gt;this&lt;/code&gt; referencing the function instead of the controller but there is a better way. We can assign &lt;code&gt;this&lt;/code&gt; to a variable called &lt;code&gt;vm&lt;/code&gt; (view model).&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; angular&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;app&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ControllerAsVmExampleCtrl1&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;$scope&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; vm &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  vm&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Hello World&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  $scope&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;$watch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; vm&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;newVal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newVal&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;Hello World&#39;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By assigning &lt;code&gt;this&lt;/code&gt; to &lt;code&gt;vm&lt;/code&gt; we solve the issue of the &lt;code&gt;this&lt;/code&gt; context. We also gain a clean looking view model for our controller. This follows more of a MVVM style pattern. We can easily see anything attached to our view model can be accessed in our view. This has become my preferred way to write my controllers on all my Angular projects.&lt;/p&gt;
&lt;p&gt;Using the new &lt;code&gt;Controller As&lt;/code&gt; syntax brings some great benefits to our code including scalability and readability of our controllers and views. I have been using this on a large scale Angular project and using this syntax has created great benefits to the code. To read more about the &lt;code&gt;Controller As&lt;/code&gt; syntax check out the docs at &lt;a href=&quot;https://docs.angularjs.org/api/ng/directive/ngController&quot;&gt;docs.angularjs.org&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>AngularJS Application Organization</title>
    <link href="https://example.com/blog/angularjs-application-organization.html" />
    <updated>2014-10-06T00:00:00Z</updated>
    <id>https://example.com/blog/angularjs-application-organization.html</id>
    <content type="html">&lt;p&gt;There are many ways to organize a Angular project. I am going to cover the ways you can structure and name your project files and the pros and cons to each. Lets first start simple. A brand new project usually starts with a &lt;code&gt;app.js&lt;/code&gt; file. This is usually where you have your app declaration, app dependencies and route definitions. When first starting out in a new Angular project this is actually a very good idea. Just starting with one file will keep things simple while you learn.&lt;/p&gt;
&lt;img src=&quot;https://example.com/assets/images/posts/2014-10-06-angularjs-application-organization/pic1.jpg&quot; alt=&quot;Simple AngularJS example with one file.&quot; style=&quot;max-width: 500px&quot; class=&quot;post-img&quot; loading=&quot;lazy&quot; width=&quot;461&quot; height=&quot;255&quot;&gt;
&lt;p&gt;Lets take our application one step further. We have been adding more to our app and now have multiple Controllers, Directives, Filters, and Services. So the next organizational method we can choose is to break our single file into multiple Angular module types. We can have one JavaScript file for each of our file types. Each for Controllers, Services, Directives, and Filters along with our &lt;code&gt;app.js&lt;/code&gt; file. All of these can live in our application folder. Now when we are looking for say a Directive we can go look into the &lt;code&gt;directives.js&lt;/code&gt; file. This is good for small applications and still keeps things relatively simple and easy to learn.&lt;/p&gt;
&lt;img src=&quot;https://example.com/assets/images/posts/2014-10-06-angularjs-application-organization/pic2.jpg&quot; alt=&quot;Simple AngularJS example with multiple file types.&quot; style=&quot;max-width: 500px&quot; class=&quot;post-img&quot; loading=&quot;lazy&quot; width=&quot;490&quot; height=&quot;275&quot;&gt;
&lt;p&gt;So looking back at organizing our modules by type what happens when we start getting multiple features? We don&#39;t want to be working on a single feature and have to sift through multiple Controllers in the Controllers file when we really&lt;br&gt;
are only focused on one thing. This leads into our next pattern, organizing by feature.&lt;/p&gt;
&lt;img src=&quot;https://example.com/assets/images/posts/2014-10-06-angularjs-application-organization/pic3.jpg&quot; alt=&quot;Simple AngularJS example with multiple features.&quot; style=&quot;max-width: 500px&quot; class=&quot;post-img&quot; loading=&quot;lazy&quot; width=&quot;488&quot; height=&quot;269&quot;&gt;
&lt;p&gt;By organizing our code by feature we can focus on the specific task at hand without having to search through code that is not relative to the feature we are&lt;br&gt;
working on. We can add all the modules related to that feature in a single JavaScript file that has a descriptive name. This means we can easily browse our application and find where exactly the code is for that feature. This is great for small to medium applications.&lt;/p&gt;
&lt;p&gt;This last pattern for organizing our Angular project is for medium to large scale applications. If our features grow to be large or complex in nature it is not wise to have a single large file for each feature. This will make it more difficult to maintain that given feature. So taking the previous method one step further we will break our features up for our Angular module types (Controllers, Directives, Services, Filters). Each Angular module gets its own file with a descriptive name inside a folder that has a well thought name for that feature.&lt;/p&gt;
&lt;img src=&quot;https://example.com/assets/images/posts/2014-10-06-angularjs-application-organization/pic4.jpg&quot; alt=&quot;AngularJS example with multiple features organized by feature.&quot; style=&quot;max-width: 500px&quot; class=&quot;post-img&quot; loading=&quot;lazy&quot; width=&quot;483&quot; height=&quot;360&quot;&gt;
&lt;p&gt;This gives us the most flexibility to grow in our application. By each feature organized by folder we can quickly drill down to the feature we are looking for. In each folder we have multiple files each containing a single module. This makes the code maintainable and lowers the cognitive overload of large code files. This is my preferred way to organize angular applications and offers the most room to grow your application.&lt;/p&gt;
&lt;p&gt;Other pros and cons to the feature based module organization exist as well. A con to this style is it complicates our build process. You would not want to include all these files individually in our application. This would cause heavy network latency to download all them separately. Instead you will want a build step to concatenate and minify all your source files and any dependencies together into a single file. This will keep your application fast and quick to download. You can use tools such a &lt;a href=&quot;http://gruntjs.com/&quot;&gt;GruntJS&lt;/a&gt; or &lt;a href=&quot;http://gulpjs.com/&quot;&gt;GulpJS&lt;/a&gt; to automate this process. These tools are build task runners your can run in NodeJS.&lt;/p&gt;
&lt;p&gt;Another advantage to the feature based and individual module files is testing our JavaScript. By organizing our files in this style we can organize our tests to match the exact same pattern. The tests can all exist in a separate folder&lt;br&gt;
form the source code. Each module file has a single corresponding test file all the test are in a single folder named by that feature.&lt;/p&gt;
&lt;img src=&quot;https://example.com/assets/images/posts/2014-10-06-angularjs-application-organization/pic5.jpg&quot; alt=&quot;AngularJS example with multiple feature folders organized by feature.&quot; style=&quot;max-width: 500px&quot; class=&quot;post-img&quot; loading=&quot;lazy&quot; width=&quot;467&quot; height=&quot;430&quot;&gt;
&lt;h2 id=&quot;iife-and-module-closures&quot; tabindex=&quot;-1&quot;&gt;IIFE and module closures &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/angularjs-application-organization.html#iife-and-module-closures&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Closures can be very important when in comes to isolating modules and bugs in any JavaScript application. As we follow the pattern of each Angular module receiving its own file I&#39;ll show you my preferred method of structuring that module. Using the Immediately Invoked Function Expression Pattern (IIFE) we can close off our module from leaking outside of its scope. Example:&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Module 1&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;controller&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;HelloWorldCtrl&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Module 2&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;helloWorldService&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This pattern creates a anonymous function that is created and executed at runtime. This isolates our modules code. This can be important from preventing name collisions when we concatenate our files together. If you notice we also have the statement &lt;code&gt;&amp;quot;use strict&amp;quot;&lt;/code&gt; in our IIFE. The &lt;code&gt;&amp;quot;use strict&amp;quot;&lt;/code&gt; is a ES5 optional property that gives us some protection against some poor design patterns. If a object or variable is used without a definition that normally would be created on the global object &lt;code&gt;&amp;quot;use strict&amp;quot;&lt;/code&gt; with cause a runtime exception protecting us from accidentally polluting the global scope.&lt;/p&gt;
&lt;h2 id=&quot;file-naming&quot; tabindex=&quot;-1&quot;&gt;File Naming &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/angularjs-application-organization.html#file-naming&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The last thing I want to cover is file naming. There are some unofficial Angular naming conventions you can follow. You do not have to follow these but just make sure your project is consistent in the naming and any team members understand this as well. First we can start with naming Controllers. A common naming pattern for Controller names and the file name is the following: &lt;code&gt;HelloWorldCtrl&lt;/code&gt; and &lt;code&gt;helloWorldCtrl.js&lt;/code&gt;. Controllers tend not follow the traditional camel case pattern you often see because a Controller is treated somewhat as a constructor. You are &amp;quot;newing up&amp;quot; a instance of that Controller at runtime. File names tend to follow camel case and the same name as the Controller. Next are services.&lt;/p&gt;
&lt;p&gt;Services follow a similar naming convention. &lt;code&gt;helloWorldService&lt;/code&gt; and &lt;code&gt;helloWorldService.js&lt;/code&gt;. Services usually end in the word Service. The file and module name follow the camel case pattern. Filters use camel case on the module name and file name. Filters are not suffixed with filter like Services and Controllers. Example &lt;code&gt;customCurrency&lt;/code&gt; and &lt;code&gt;customCurrency.js&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The last naming convention to cover is Directives. Directives when registered in the Angular application are camel case, &lt;code&gt;phoneValidate&lt;/code&gt;. This Directive when used in the HTML follows snake case, &lt;code&gt;&amp;lt;input phone-validate /&amp;gt;&lt;/code&gt; (Angular handles the conversion and expects this format). The filter source file follows the Snake Case format, &lt;code&gt;phone-validate.js&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So we have covered naming our angular modules and defining our file structure based on our application size. There are many ways to set up a Angular JS application just remember stay consistent and try to follow the community conventions whenever possible.&lt;/p&gt;
&lt;h3 id=&quot;tl%3Bdr&quot; tabindex=&quot;-1&quot;&gt;TL;DR &lt;a class=&quot;post-anchor&quot; href=&quot;https://example.com/blog/angularjs-application-organization.html#tl%3Bdr&quot; aria-label=&quot;heading permalink&quot;&gt;&lt;svg width=&quot;36&quot; height=&quot;30&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M17.6 24.32l-2.46 2.44a4 4 0 01-5.62 0 3.92 3.92 0 010-5.55l4.69-4.65a4 4 0 015.62 0 3.86 3.86 0 011 1.71 2 2 0 00.27-.27l1.29-1.28a5.89 5.89 0 00-1.15-1.62 6 6 0 00-8.44 0l-4.7 4.69a5.91 5.91 0 000 8.39 6 6 0 008.44 0l3.65-3.62h-.5a8 8 0 01-2.09-.24z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M28.61 7.82a6 6 0 00-8.44 0l-3.65 3.62h.49a8 8 0 012.1.28l2.46-2.44a4 4 0 015.62 0 3.92 3.92 0 010 5.55l-4.69 4.65a4 4 0 01-5.62 0 3.86 3.86 0 01-1-1.71 2 2 0 00-.28.23l-1.29 1.28a5.89 5.89 0 001.15 1.62 6 6 0 008.44 0l4.69-4.65a5.92 5.92 0 000-8.39z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; d=&quot;M0 0h36v36H0z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;all one file in app.js&lt;/li&gt;
&lt;li&gt;all in one folder, multiple files ordered by type&lt;/li&gt;
&lt;li&gt;all in one folder, multiple files ordered by feature&lt;/li&gt;
&lt;li&gt;multiple files and folders organized by feature and type&lt;/li&gt;
&lt;li&gt;follow some sort of naming convention early on&lt;/li&gt;
&lt;li&gt;each file should be singe module/feature in IIFE with strict mode&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>JavaScript ES6 let</title>
    <link href="https://example.com/blog/javascript-es6-let-statement.html" />
    <updated>2014-10-30T00:00:00Z</updated>
    <id>https://example.com/blog/javascript-es6-let-statement.html</id>
    <content type="html">&lt;p&gt;There are some very exciting features coming to JavaScript over the next few months in ES2015 or known as ES6. Not all browsers support all of the new ES6 feature set but you can use a transpiler such as &lt;a href=&quot;https://babeljs.io/&quot;&gt;BabelJS&lt;/a&gt; or TypeScript to transpile ES6 to working in the browser ES5. Browsers are actively working on these features and some you can try out today.&lt;/p&gt;
&lt;p&gt;This post I am going to cover the &lt;code&gt;let&lt;/code&gt; statement. &lt;code&gt;let&lt;/code&gt; brings some new functionality that will help keep our code from falling into some of JavaScript&#39;s tricky parts.&lt;/p&gt;
&lt;p&gt;JavaScript ES5 and earlier has function scoping available. It turns out you can do just fine with function scope but programmers coming from a Java or C# background may get tripped up from using block scoping. So lets look at a example.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; bar &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; bar &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Same variable&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bar&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;1&#39;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this example &lt;code&gt;foo()&lt;/code&gt; returns 1 even though the inner bar assignment is in the &lt;code&gt;if&lt;/code&gt; block. This is because the inner bar assignment is not scoped to the &lt;code&gt;if&lt;/code&gt; block but rather the function. This can be a common source for bugs. In JavaScript any variables declared in a function are hoisted to the top of the function. So the previous example is behaves as if you wrote it in the following format.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; bar &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; bar &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    bar &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Same variable&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bar&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;1&#39;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The inner bar is hoisted to the top of the function then reassigned to equal one in the inner block. Another common case of this behavior is in &lt;code&gt;for&lt;/code&gt; loops.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;hello&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Same variable&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Same variable&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;1 2 3&#39;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;3&#39;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We get back 3 instead of &#39;hello&#39; because our &lt;code&gt;i&lt;/code&gt; variable was hoisted to the top of the function. As you can see this can cause confusion and introduce bugs into our code. So using the new ES6 &lt;code&gt;let&lt;/code&gt; statement we can solve some of these issues.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;hello&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Different variable&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Different variable&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;1 2 3&#39;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &#39;hello&#39;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using &lt;code&gt;let&lt;/code&gt; we can block scope our variables and prevent them from being hoisted. Using &lt;code&gt;let&lt;/code&gt; also prevents the accidental creation of duplicate variables. We will get a error if we have two variables named the same and declared with &lt;code&gt;let&lt;/code&gt; within the same block. &lt;code&gt;var&lt;/code&gt; would of silently&lt;br&gt;
and override the first declaration.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bar&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// ReferenceError&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; bar &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; bar&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; bar&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// TypeError&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once you start using ES6 its recommended to always use &lt;code&gt;let&lt;/code&gt; over &lt;code&gt;var&lt;/code&gt; for variable creation. This will help keep consistency and prevent confusion of the two. &lt;code&gt;let&lt;/code&gt; and many other ES6 features will make JavaScript easier to maintain and use for the future.&lt;/p&gt;
</content>
  </entry>
</feed>