0 Comments

At the Mix10 conference, the Windows Phone 7 teams had some very big announcements – a lot of it had been kept secret and first revealed to the public now. There is however still some details they keep secret. Some of these secrets are the user agents of Internet Explorer for Windows Phone 7, which they simply wouldn’t give us.

After playing with Windows Phone 7 we managed to secure a copy of the user agent string. The user agent for IE on Windows Phone 7 running on the Asus Galaxy device is:

Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) Asus;Galaxy6


Notice that it identifies the browser as IE7 and the operating system as Windows Phone OS 7. The IE team told us that the browser in Windows Phone 7 is a mobile version of IE7 with certain features ported from IE8. So it doesn’t use the full Trident 4 layout engine that IE8 uses, but instead Trident version 3.1 with a few extra capabilities.

The user agent was retrieved from server logs, so it is the actual user agent from the actual browser.

0 Comments

A few weeks back i found out that the method I use to minify CSS was about 5% more efficient than the YUI Compressor. I tweeted about it and was encouraged to post the code that does the actual minification.

public static string RemoveWhiteSpaceFromStylesheets(string body)

{

  body = Regex.Replace(body, @"[a-zA-Z]+#", "#");

  body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty);

  body = Regex.Replace(body, @"\s+", " ");

  body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1");

  body = body.Replace(";}", "}");

  body = Regex.Replace(body, @"([\s:]0)(px|pt|%|em)", "$1");

 

  // Remove comments from CSS

  body = Regex.Replace(body, @"/\*[\d\D]*?\*/", string.Empty);

 

  return body;

}

 

The method takes a string of CSS and returns a minified version of it. The method have been modified for demo purposes, so you might want to optimize the code yourself.

0 Comments

I wanted to try something new this time, so I recorded my blog post as a screencast. Since I mostly write about code I thought it might be a good way to illustrate it in a video instead of in writing. It does add a new level of simplicity and understanding to the message. Please check it out and tell me if you like the video more than a regular blog post.

[vimeo:8338567]

I hope the video illustrates just how easy it is to embed images in stylesheets and also how to use the online tool for image to base64 conversion.

0 Comments

My grand plan of 2009 was a new year’s resolution that would take me around the world. The plan was simple:

In average, I need to visit a new country that I may have visited before, every month of 2009.

Last time I wrote about my plan on this blog, I just got home from Greece and Albania in July and the plan looked to succeed. According to my original plan, I had to go to Egypt and Monaco this fall, but unfortunately that never worked out. So instead, here’s how the grand plan of 2009 ended.

August

This was a good month that began with a trip to the Fringe Festival in Edinburgh, Scotland with one of my Scottish friends. It’s the world’s biggest arts festival and a lot of fun with hundreds of venues. I saw some excellent comedy acts.

Mads Kristensen in Edinburgh

A week later I did a major travel mistake – underestimating jet lag. I flew to Boston on a Friday morning and back home Sunday afternoon. So a small trip with an 8 our flight both ways. I landed in Copenhagen airport Monday morning at 9am and went directly from the airport to the office. I won’t do that ever again. Well, I probably will…

Mads Kristensen in Boston

September

The plan here was to go to Monaco and win big on the casinos, but alas, my travel buddy backed out.

October

It proved that the best trips in 2009 where the last two ones. In the middle of October I took a 12 day guided tour through the major cities and sites of Iran - Tehran, Shiraz, Isfahan, Yazd and Qom. Iran is filled with sights and relics from the Old Persian Empire and it totally changed my views on Iran. I also got the chance to meet Keyvan Nayyari in Tehran.

Mads Kristensen and Keyvan Nayyari

On the way home, we had time in transit in Istanbul airport in Turkey. So we ventured out to see the Blue Mosque and the Bosphorus Strait. It was also in Istanbul we had our first beer in 12 days, because alcohol is banned in Iran.

 


November

My parents were invited to a wedding in India and as soon as I heard, I wanted to tackle along. I’ve seen pictures of Indian weddings before and there was no way I would miss that opportunity. The groom was so kind to invite me as well and another big adventure unfolded. Only 2 weeks separated the trip to Iran and India. We started at the Fort Aguada resort in Goa for a couple of days before the wedding, then 4 days of constant partying with the bride and groom and then a few days in Mumbai before heading home.

Mads Kristensen in Mumbai

Conclusion

And with this the grand plan of 2009 succeeded and my goal was reached. Here’s a list of the destinations I visited in 2009 in chronological order

  1. Düsseldorf, Germany
  2. London, England
  3. Chişinău, Moldova
  4. Seattle, Washington
  5. Malmö, Sweden (this one doesn’t count since it’s a ½ hour drive from where I live)
  6. Malaga, Spain
  7. Gibraltar
  8. Stirling, Scotland
  9. Amsterdam, Holland
  10. Corfu, Greece
  11. Sarande, Albania
  12. Edinburgh, Scotland
  13. Boston, Massachusetts
  14. Tehran, Iran
  15. Mumbai, India

According to TripIt, that amounts to 73.000 kilometers which is almost twice around the world.

For 2010 my plan is more relaxed. So far I have planned a trip to South Africa, Las Vegas and Seattle – a mix of business and pleasure. Also, for summer my dream is to take the Transsiberian Railway through Russia to Mongolia and China, but no plans yet.

0 Comments

A few days ago, Google released their Closure Compiler project for optimizing JavaScript. Here’s what they write about the Closure Compiler:

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left.

The interesting part of the Closure Compiler is that it not only removes whitespace, it also rewrites your JavaScript code to make it smaller and optimizes the code for better performance. My tests show that it can reduce JavaScript files by about 60% - and that’s before HTTP compression! Considering how much JavaScript a modern website uses, this is no less than amazing and highly useful.

The Closure Compiler comes in two flavors – a Java based command line tool and a RESTful API. I’ve been playing around with the API and it works great and very fast.

The code

The C# class I’ve written takes a JavaScript file and passes it through the API and then returns the compressed JavaScript as a string. The class contains one public and one private method and is only 47 lines of code including 16 lines of comments.

public string Compress(string file)

{

  string source = File.ReadAllText(file);

  XmlDocument xml = CallApi(source);

  return xml.SelectSingleNode("//compiledCode").InnerText;

}

 

private static XmlDocument CallApi(string source)

{

  using (WebClient client = new WebClient())

  {

    client.Headers.Add("content-type", "application/x-www-form-urlencoded");

    string data = string.Format(PostData, HttpUtility.UrlEncode(source));

    string result = client.UploadString(ApiEndpoint, data);

 

    XmlDocument doc = new XmlDocument();

    doc.LoadXml(result);

    return doc;

  }

}

How to use it

You can use the class to do various cool things. You can write a MSBuild or NAnt script that automatically compresses your JavaScript files as part of a continuous integration process or, as I prefer, write a HTTP handler to do the same but at runtime. Remember to output cache the compressed result. Here's an example of using the class from ASP.NET:

GoogleClosure gc = new GoogleClosure();

string script = gc.Compress(Server.MapPath("~/script.js"));

Remember that the class doesn't do any exception handling, so you might want to stick that in yourself.

Download

GoogleClosure.zip (905,00 bytes)