05
Dec 11

Amazon CloudFront with IIS7

Recently I have been working on a CSS & Javascript bundle called “Jon Kragh Starter” that I created as a starting point for all of my web projects.

I turned to Amazon’s CloudFront service as a CDN for my JS & CSS files.  Amazon won for me because I need SSL, and their offering was the cheapest in that regard.

My site is hosted on Windows Server 2008 R2 Standard with IIS 7.5.  Setting up Cloud Front was easy.  I simply pointed it to my site as a “Custom Origin” and then 10 minutes later, I was about to view my content under the URL that CloudFront generates.

image

The biggest challenge was to get CloudFront to serve my gzipped css and JavaScript.  CloudFront will serve Gzipped content if your origin server returns gzipped content to CloudFront, when CloudFront requests it with the user’s headers.

So first and foremost you need to ensure your origin server serves Gzipped content.  Here is an example at my origin.  Using Firebug’s network tab you can inspect the response headers:

SNAGHTML138c082a

The trick is to get CloudFront to serve the same Gzipped content.  It turns out that IIS will not return gzipped content to CloudFront in its default configuration.

Many thanks to this thread for pointing me to the correct solution.  What worked for me was to add the flags noCompressionForHttp10="false" noCompressionForProxies="false" to the server’s applicationHost.config file followed by a global “iisreset” from the command line.

Keep in mind during your testing, you will need to add new files to your server when you retry to see if you get your gzipped content from CloudFront.  This is because CloudFront caches your content.  There is a way to invalidate it through their API, but it’s much simpler to just add another js file (e.g. test with test1.js, then copy it & rename, and test with test2.js etc).

File:  C:\Windows\System32\inetsrv\config\applicationHost.config

(Unfortunately this did not work for me in a regular application level web.config and it needed to be done at the server level).

image

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" noCompressionForHttp10="false" noCompressionForProxies="false">
  
            <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
            <dynamicTypes>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/x-javascript" enabled="true" />
                <add mimeType="*/*" enabled="false" />
            </dynamicTypes>
            <staticTypes>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/x-javascript" enabled="true" />
                <add mimeType="application/atom+xml" enabled="true" />
                <add mimeType="application/xaml+xml" enabled="true" />
                <add mimeType="*/*" enabled="false" />
            </staticTypes>
        </httpCompression>

iisreset

image

 

CloudFront JavaScript Gzip Test

My Origin

https://www.jonkragh.com/starter/v/1.0/foot-complete.js

SNAGHTML138c082a

Cloudfront gzip encoded javascript

https://d2yljticlotdgz.cloudfront.net/starter/v/1.0/foot-complete.js

SNAGHTML137bbb7f

 

CloudFront CSS Gzip Test

Origin

https://www.jonkragh.com/starter/v/1.0/starter.css

SNAGHTML137f09b0

Cloudfront

https://d2yljticlotdgz.cloudfront.net/starter/v/1.0/starter.css

SNAGHTML137e58fd

I’m now enjoying blazing speeds.  Here is an example of Ctrl F5 the same JS file from my server (I am in NJ, my Server is in Denver).

Directly from my origin server

SNAGHTML13a218f8

The same file from CloudFront

SNAGHTML13a2a970

07
Oct 11

What makes good code?

I see a problem time and time again with programmers wasting an incredible amount of time writing “good code” when in reality sometimes that “good code” isn’t good at all.  I fall prey to this as well, so I’m going to write up this post to put into words the code design decisions that I make subconsciously when trying to write “good code”.  That way I can analyze it, and refine it in the future.  This post is focused on the code itself, not whether or not the software product is of any use. At the end of the day the hardest thing to do is to create something that people want to use. That is a totally different topic.

What can I say? After 15 years of programming professionally, I’m a pretty confident coder. I work hard at it, and still find ways to improve everyday.

As Bradley Nowell so eloquently stated in “Love is What I got”….

“I can play the guitar like a mother f-in riot.” – Sublime

Well this is how I feel about code!

“I can rock the compiler like a mother f-in riot.” – Jon Kragh

Continue reading →

12
Aug 11

Jon Kragh’s Week in Review August 12th, 2011

I am going to do a stream of consciousness every Friday for the next month and see how it goes. Once I wrote the post, I’m going to video tape myself talking about it.  So here it goes!

Here is a video about the post below.

01
Apr 11

Dog Ringworm Photos, Diagnosis, and Cure

Disclaimer: I am not an expert on Dog Ringworm, I am just a dog owner that wants to share our success story!

Adoption

This past summer we adopted our amazing dog Lilah from a doggy foster mom named Shilpa. Shilpa had rescued Lilah from the Liberty Humane Society. When we got Lilah, Shilpa told us that we would need to go to the vet to have Lilah’s rash checked on (Shilpa had Lilah less than a week and was using topical cream which seemed to help a bit on the rash).

Here is a pic of the first day we got Lilah, notice the rash on her right rear leg.

IMG_1884 Continue reading →

01
Nov 09

The Poor Man Buys Twice – Why More Expensive is Oftentimes Cheaper

One of my old co-workers Val had a great Russian saying that was translated as: “the poor man buys twice”.  It means that when you buy something cheap, it will not last as long as the more expensive option and often times costs you more in the long run (since you have to buy it twice).  We live in a society where so many things are now throw-away items.  I am finding more often than not that cheaper options are generally more expensive in the long run for all kinds of things.

Here is an example of this old saying proving true for me this weekend.  Below is a photo that shows my rusty old shower caddy $19.99 and my new simplehuman shower caddy $103.99 after coupon.

shower

Continue reading →

29
Oct 09

Rendering an ASP.net UserControl to a String

I have been converting one of my side projects from ASP.Net WebForms to ASP.Net MVC.  In order to reuse some of my existing ASP.net UserControls from WebForms in ASP.Net MVC, I tweaked a rending method found here and here.

I improved on these methods by enabling the caller of the utility function to be the one to set properties on the UserControl in a strongly typed fashion. The is no reflection or any other special interface needed on the user control.  The key was adding a callback.

Here is what it looks like to call and render the control to a string by the caller.  In this example I am rendering my GoogleMap UserControl to a string.  The last argument I am passing is an anonymous method that is called by the utility function to initialize my control.

UIUtil.RenderUserControl<GoogleMap>("~/UserControls/GoogleMap.ascx",
    uc =>
    {
        uc.CollegeToShow = CollegeToShow;
        uc.Height = Height;
        uc.Width = Width;
        uc.Mode = Mode;
    });

Continue reading →

28
Jul 09

Twitter Syntax / Commands – Facebook should also support them

Something that amazes me on Twitter, is that regular humans (non-Twitter-Hashtag programmers) are fine with, even good at adding little markup tags in tweets.  So now that we have seen that the masses are cool with adding little tags and markup to freeform content, we should embrace it!

Since Facebook is the leading social network, they should also support a markup syntax in comments & status updates because it is useful for humans and computer programs. Continue reading →

09
Jul 09

How to get Google to index only part of a Webpage

As of today, there is no way to explicitly have Google index only certain parts of a single Webpage.  I am writing this post in order to show my need for partial page indexing support and to discuss a few possible solutions for this today.  iStock_000005882596XSmallMy need for this stems from the Personalization of WebPages, a feature that makes the web better for people.  I hope that this post can create discussion between us and maybe someone from Google will be kind enough chime in and provide us with guidelines on how to design websites where we want Google to ignore parts of a WebPage in their index.

Continue reading →

07
Jul 09

Setting up a Headless iTunes Server

In my home office, I have a headless server running Windows

IMG_4650

Server 2008 with iTunes 8 installed.  This machine is where I store all of my music, photos, videos, and other entertainment related files.  The interesting thing is that I also use this server to wirelessly broadcast my iTunes music digitally to my kick-ass home studio setup (a Benchmark DAC1, Coleman Audio M3, Quested Powered F11As, and a REL Subwoofer). The setup that I am about to describe should work equally as well for those of you who have any kind of audio playback equipment that has an optical audio input.

Continue reading →

02
Jul 09

My Journey to Google

copybeanbagRecently, I had the great honor of being asked by Google to present at Google I/O 2009.  Here is the story of my journey including: how to get noticed by Google, getting invited to present at Google I/O, practicing the presentation with my Google contact, the hours leading up to the presentation, the presentation itself, and the after party!  I have included some behind the scenes photos and videos as well.

Continue reading →


s