Tag Archives: javascript

ASP.NET and HTML5 Local Storage

I came across an informative blog post today by Stephen Walther that talks about ASP.NET and HTML5 local storage. It explains this exciting feature by discussing details relating to client/server concurrency, difference between local storage and cookies, intracting with WCF and more. If you are an ASP.NET developer who wants to stay on top of things go check it out.

Thank You Apple, Finally Some Clarity

Apple Logo

Today Apple finally gave developers some clarity regarding their previously ambiguous and arbitrary App store acceptance polices. This was a tough one because developers could potentially spend lots of time developing an app only to have Apple reject it. Apple states, "we don't need any more fart apps". I couldn't agree more. Apple's language was honest and direct which, as a developer, I expect to prevent wasted time and money.

They also removed a section from their developer agreement that essentially prohibited app development with anything other than Xcode. I have been kicking around the idea of developing apps for a while but I did not want to marry a single platform. I also didn't want to learn Objective-C which is, in my opinion, an arcane programming language from the '80s. I'm looking forward to developing for Android, iOS, and the rest leveraging my C# or JavaScript skills.

Some say that Apple's old policy could have spurred antitrust inquires and eventually lawsuits. Personally I don't care why they changed course and ate crow. I'm just glad Apple is respecting developers by providing them with information and access to tools to get the job done efficiently and in the manner we choose.

JavaScript and CSS Minification and Optimization with Visual Studio and YUI Compressor

About a year and a half ago I got very interested in JavaScript optimization. This interest was born after playing with YSlow for Firebug (Firefox). I noticed that my customer’s homepage was requiring my browser to download 2 megabytes of Images, HTML, CSS, and JavaScript. Having gotten my start in the days of modems I was aghast at the bandwidth requirements of this huge site. At the time this customer was receiving millions of hits a day due to a recent influenza outbreak. Do the math, that’s a lot of data.

YSlow recommended that the JavaScript and CSS be minified. I’d see this before with jQuery and other open source JavaScript examples. Minification is essentially a way to remove unnecessary characters and white space from the code with the goal of serving the smallest possible file over the wire to the client browser. The problem is this renders code unreadable to developers. I wondered if there was a way Visual Studio could handle this during deployment. Turns out that there is a free add-in for Visual Studio from Microsoft, Visual Studio Web Deployment Projects, which provides more advanced compilation options. The next step was to find code that Web Deployment Projects could use to perform the minification.

The “Y” in YSlow stands first for Yahoo so I went to see what they had to offer. They have open source code know as the YUI Compressor Library available for download that performs JavaScript and CSS minification. The problem for me was the code I needed was written in Java which is not simple to integrate into a Visual Studio build process. Fortunately someone had ported it to C# and thrown it up on CodePlex. It’s currently stable at version and based on version 2.4.2 of the YUI Compressor.

The mix of Web Deployment Projects and YUI Compressor is the most efficient method for me. I don’t have to think about it because it’s integrated to my deployment build process. It provides the flexibility to either minify the files individually or merge them into one large file that my visitors only have to download one.

The customer mentioned at the beginning of this post was able to reduce the size of their JavaScript and CSS by almost 50% (1MB per unique request). This is a simple way to help your servers handle their own pandemic flu outbreak, or “slashdotting”, as efficiently as possible. Your sites will also be much more snappy as browsers are not having to parse unnecessary whitespace, comments, etc. It’s the closest you’ll get to compiling JavaScript and CSS, all for free.


Example of JavaScript Minification

Javascript before minification

Javascript after minification

Example of CSS Minification

CSS before minification

CSS after minification