#.think.in
learn.create.enjoy

#.think.in infoDose #4 (20th Oct - 25th Oct)

October 27, 2008 09:22 by brodie

Notable Events

Silverlight

Architecture

ASP.NET AJAX

ASP.NET MVC

jQuery

Testing

Usability

Developer Skills

Singularity Watch

Other

Tips


#.think.in infoDose #3 (13th Oct - 17th Oct)

October 20, 2008 08:15 by brodie

Notable Events

Management/Process

Architecture

ASP.NET

Silverlight

Other

Singularity Watch

Books to Read

Quotes

  • "An engineer will endlessly tinker with a project as long as it's sitting in front of them. Endlessly" - rands (twitter)
  • "There ain’t no rules around here. We’re trying to accomplish something." —Thomas Edison

#.think.in Info-Dose #2 (5th Oct - 10th Oct 2008)

October 13, 2008 08:17 by brodie

Agile/Management/Process

 

Architecture

 

ASP.NET

 

Silverlight/WPF

 

jQuery

 

Singularity Watch

 

Other

 

Quotes

You’ll always miss 100% of the shots you don’t take.” - Wayne Gretzky


#think.in Weekly Info-Dose #1 (29th Nov - 3rd Oct 2008)

October 6, 2008 08:18 by brodie

 

I've been meaning to put a weekly linkblog together for a while, and now that I've established a daily web scouring routine to satisfy my info-junkie addictions, I thought it was about time.

The world doesn't need another linkblog rehashing the same information again and again ... this is true.  So my intentions for this (hopefully semi-regular) post are this;

#1 - I read many link blogs/rss feeds a day - essentially the first half hour of my day is catching up on all my information sources - generally from rss feeds or twitter feeds.  There is just too much out there to take in all at once... but certain things jump out at me.  Scanning these feeds becomes a bit of a skill (habit), and one which many choose not to develop. There are still plenty of developers out there (even in my own team!) that don't read blogs/rss feeds/etc. which astounds me somewhat. Some of the reasons for not doing this include the information overflow becoming too overwhelming - which I'm sure that there is some kind of psychological condition for this??  So I figured if I could provide a bite-sized summary of the weeks information then it may help others to develop their information addiction on a lower level.

#2 - I tend to bookmark interesting items using delicious and Evernote, which are both great tools.  Delicious is great as I can access my links from anywhere, but lately I found it (or the plugin i'm using) to be a little unreliable - as in I was sure I book marked this certain site, but now I can't find it.  Evernote on the other hand is also great for keeping bookmarks plus other notes, images, etc... but I use the desktop version because it's quick and easy and therefore I can't access my work notes from home for example. (if I could somehow sync my desktop Evernote to the web Evernote that would be awesome!!)  So another reason for this link blog is for my own personal references to the links I find useful/interesting, and being able to access them again from my blog.

#3 I'd like to develop a habit of writing more often and keeping the blog site updated.

 

I've posted before about my top 10 rss feeds that every developer should read, but if you can't get onto those then hopefully this will summarize the best links from them (IMHO).

Anyways, enough rambling for now, and to our five hardcore sharpthinking feedburner readers out there, enjoy! ;-)

 

Notable Events

Agile/Management/Process

ASP.NET MVC

Silverlight

jQuery

Singularity Watch

Other


YSlow Performance Grade Improvements : Gzip components

July 18, 2008 14:10 by brodie

Up until now adding useful features to our ASP.NET IIS 6.0 hosted site has been the main driving force.  Recently though, as our web site begins to take on a greater user load, performance, optimization, and scalability are becoming more of a focus for us.

I've had Firebug installed on FireFox3.0 for some time now, which is an essential tool if you are a web developer, or designer for that matter. I can't tell you how much easier it's made debugging javascript and and fiddling around with CSS.

Recently I installed YSlow which is a plugin for the Firebug plugin (*vision*: a chain of double adapter plugs)  - it allows you to determine why your pages are slow (and they will be) and gives you some rules for speeding it up ... as defined by the Yahoo crew.

So I ran YSlow and this is the current state of play ... a big fat 'F' - FAIL! That simply won't do, so my goal over the next few weeks will be to get an 'A' grade.

image

 

The first item I thought I'd look at is Gzip components.

What is gzip? Basically it a file compression program that's supported by most browsers and web servers and allows you to serve up compressed http, therefore potentially making downloads a little faster.  You can read all about it on wikipedia.

 

So how do you turn it on?

Well here's what I did for IIS 6.0. (When we switch to IIS7.0 I provide an update)

Well, as usual, search the internet and found these useful resources at MS TechNet, Coding Horror, and Scott Forsyth's Blog.  Read all these and you'll be an IIS 6.0 Http Compression master! There are many scenarios and more advance things you can do but I'll list below the simple steps I took to get it working...

 

Step 1. Turn on Http compression in IIS 6.0

Right click on your Web Sites folder, go to properties  and open up the 'Service' tab and make it look like this...

image

 

Step 2. Allow direct metabase edit

Next we'll go and edit the IIS metabase so if you don't want to shutdown IIS then right click on the IIS Server node, go to Properties and enable Metabase Edit.

image

I'm sure that there are security problems with leaving this switched on so switch it back off after you've done your edit in step 3. Easy.

 

Step 3. Edit the Metabase.xml

Open the C:\Windows\system32\inetsrv\metabase.xml file in notepad.

Find the IISCompressionScheme sections and change them to look like this...

<IIsCompressionScheme    Location ="/LM/W3SVC/Filters/Compression/deflate"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="0"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="FALSE"
HcDynamicCompressionLevel="9"
HcFileExtensions="htm
html
txt
js
css"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe
aspx
asmx"
>
</IIsCompressionScheme>
<IIsCompressionScheme    Location ="/LM/W3SVC/Filters/Compression/gzip"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="1"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="9"
HcFileExtensions="htm
html
txt
js
css"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe
aspx
asmx"
>
</IIsCompressionScheme>

 

Obviously there are a few things to try in here (read the resource links above for more info) but all I did was change the HcFileExtensions, HcScriptFileExtensions, and the HcDynamicCompressionLevel.

 

Note: There are alternatives to editing this file directly like using the Adsutil.vbs, I tried some of the suggestions but it wasn't working for me initially (i'm sure it was something simple), so I moved on to editing the file directly ... much easier.

 

Step 4. Reset IIS

Now checking my YSlow results again and, ... only get a 'B' grade! WTF! Apparently this is because we're using MS ASP.NET AJAX and the WebResource.axd won't compress, hmm I did some searching and found that there were a few options available to me, so I checked out MbCompression on CodePlex.

 

Step. 5 Compress WebResource.axd

Do this by following his instructions here.

(UPDATE: The correct instructions can be found in the source code download from CodePlex)

Unfortunately though he indicates the wrong namespace to use  (Miron.Web.HandlersAndModules) ... so with the help of Reflector I found the correct namespace (Miron.Web.MbCompression).  To get the basic compression happening modify your web.config ... it should look something like below ...

 

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, "/>
<add name="PageCompressionModule" type="Miron.Web.MbCompression.PageCompressionModule"/>
<add name="WebResourceCompressionModule" type="Miron.Web.MbCompression.WebResourceCompressionModule"/>
</httpModules>

 

Now, run YSlow again ... overall Performance Grade of 'D' (60) ... which is not great,  but better than a fail.  And now if you check out the Gzip components ... grade 'A'!!

 

image

 

The MbCompression seems to have a few more tricks up it's sleeve which I will try to use to minify js and css.

 

Next Time : Minify JS, Put JS at the bottom, and Put CSS at the top.


AdRotator: Json serialization

June 15, 2008 18:46 by tarn

This article is part of a series of posts about various aspects of writing web controls for ASP.Net using an ad rotator as an example. The AdRotator WebControl Example post has links to related posts and downloads.

The AdRotator needs to pass some data to the client side code so I use a Json serializer. I use the same class we use on the server side. The Json serializer converts an instance of it, or in our case a templated list of it, to a sting on JSON we can emit in the output. Json is JavaScript Object Notation and literally describes an object in Javascript that we can use in our client side Javascript code.

The object is very simple and only contains three strings and constructors. I have removed some of the attributes described in other articles as they are not relevant in this context.

public class ImageItem
{
    public ImageItem()
        : this(string.Empty, string.Empty, string.Empty)
    {
    }

    public ImageItem(string linkUrl, string imageUrl, string displayTime)
    {
        LinkUrl = linkUrl;
        ImageUrl = imageUrl;
        DisplayTime = displayTime;
    }

    public string LinkUrl { get; set; }
    public string ImageUrl { get; set; }
    public string DisplayTime { get; set; }
}

 

The AdRotator has a public property Images that is List of the ImageItem type above.

public List<ImageItem> Images;

 

During the RenderContents event of the AdRotator we can serialize this list into a string of Json.

JavaScriptSerializer serializer = new JavaScriptSerializer(); 
string json = serializer.Serialize(Images); 
 

The Json will look something like this.

[{"ImageUrl":"Images/Winter.jpg","LinkUrl":"#","DisplayTime":"1000"},
{"ImageUrl":"Images/Sunset.jpg","LinkUrl":"#","DisplayTime":"4000"}]

The following script and corresponding output will hopefully demonstrate how we can use the Json on the client side as data.

var imageList = [{"ImageUrl":"Images/Winter.jpg","LinkUrl":"#","DisplayTime":"1000"},
                 {"ImageUrl":"Images/Sunset.jpg","LinkUrl":"#","DisplayTime":"4000"}];

for(var i=0; i<imageList.length; i++)
{
    document.writeln(imageList[0].ImageUrl);
}

Output:

Images/Winter.jpg 
Images/Winter.jpg

 

Well that's all the information I'm going to include in this article. I'd like to go further into how the Json is used in the AdRotator but I've rambled on long enough. I think there is enough here to see that Json is a pretty cool language for communicating data between the server and client side Javascript.

I should also note that the JavaScriptSerializer is marked as depreciated and points towards the DataContractJsonSerializer. I briefly tried to get this working, but I couldn't seem to find the object in my system assemblies. To read more about that, check out DataContractJsonSerializer in .NET 3.5 that discusses using the DataContractJsonSerializer.

I hope you've found the article interesting, if you have you might be interested in reading more article about the AdRotator example or you might want to download and checkout the example project.