Musielak Marek

Posted on Tuesday, January 27, 2009 by Marek Musielak

Internet Explorer 6 - Web Developers Nightmare

I finally have a short break from fixing bugs and writing C# code. I'm creating new templates for one of our products instead. Yeah, I know, developers should not be responsible for html and css stuff. However I do really want to diversify into new areas, cause no one knows what future will bring to us. So I started my work. It's a pretty relaxing activity. No compiling, no complexity - just html, Firebug and me. I wish it were so easy...

Opera, Safari, even Chrome - everything looks smooth. Then I opened what I'd created in IE7. Few fixes and it looks exactly as I wanted. I did it even without Developer Toolbar. I was nearly there - just one last glance in IE6 (Multiple IE is veeeery useful here). Well said "one last glance"... Layout of the page is completely crashed. I feel like I'm writing the page from the scratch. 4 additional lines in <head />:

<!--[if IE 6]>
<link rel="stylesheet" href="/Styles/ie6.css" type="text/css"
media="screen" title="IE bugfixes" charset="utf-8" />
<![endif]-->

and here we go. "display: inline-block", "border-collapse: collapse" (a friend of mine, master of design, didn't even know that such an attribute exists), "clear: both; overflow: hidden;" nearly everywhere. Is my template so wrong? Or maybe it's the "browser". Heh "browser" - maybe I should not even call it with this word.

Maybe if I catch a goldfish or find Alladin's Lamp, I will have a wish "No IE6!". Maybe if I concentrate really hard... Ehhh who I'm trying to cheat. Hope often blinks at a fool. Let's check the reality. Fortunately I have an access to the real data - our products :) Let's look at a sport portal first - over milions page views per day - it seems to be a good place to check stats.

Sport portal users
BrowserPercentage
IE 732.7%
IE 624.7%
Firefox 311.2%
Unknown8.0%
IE 5.55.9%
Mozilla 55.3%
Safari4.1%
Mozilla 42.7%
Firefox 21.4%
Opera 91.5%
IE 8.00.5%
......

Nearly 25% users with IE6? I hoped it would be significantly less. And who still has IE 5.5? Maybe it's because of the fact that 50% of visitors are form UK and about 10% from both USA and Nigeria. Maybe rest of the world prefers other browsers? Let's check another site - 10k users per day, 26% from Canada, 8% from Span, 4,5% from Philippines, 4% from Lithuania, all other countries less than 1%. Yeah this is really international site.

International site users
BrowserPercentage
IE 6.045.9%
IE 7.032.3%
Firefox 3.09.2%
Netscape 4.04.1%
Mozilla 5.02.5%
Unknown 0.02.1%
Safari 5.01.3%
Firefox 2.01.2%
......

Looks like the world loves IE6. Maybe because it's very slow, maybe because it doesn't display properly thousands of pages, maybe ... I don't even want to guess their reasons. The truth is as you see above. I wish I were allowed to put a big banner on all the sites that my company creates, saying "Still using IE6? With other browsers surfing will be funnier and faster. Don't believe? Try one of the links ... " and display it whenever browser is recognized as IE6 or lower.

Wanna know my opinion? We will never be able to stop supporting IE6. You probably know that old code never dies. I must worry you, old browser never dies neither.





Shout it
Read More »

Posted on Sunday, January 25, 2009 by Marek Musielak

Internal server errors handling

"Page could not be loaded". "Internal server error". Arghhhh ... When I see such a message on the website I feel like leaving the site hastily and never come back. The worse is when this is a site that I've built ... Ok, I can cope with this when I'm the one who tried to open the page. But what when I don't know that on the site that I'm responsible for, someone gets such a message every minute? And visitors one by one give up entering this page. Yeah, this is a serious problem.

Let's do something with this. Sure, we can create custom error page (like I described it for 404 error here). It would look nicely and inform user that our site encountered some difficulties and that we will deal with them soon surely. Yeah, but we're not able to fix the problem if we don't know about it. Solution seems to be pretty obvious - let's send an email to us informing that the page doesn't work. But what if when we'll try to open the page later, it will be up and running again? Or if the page crashes only in some particular circumstances that we won't be able to reproduce?

It would be really good to know about every error on the site no matter who tried to browse it. We can use Application_Error handler here. The Application_Error event handler is specified in the Global.asax file of the application. This handler is called whenever an unhandled exception is thrown in your application. So let's add this handler and send a notification error every time when something is wrong on our site.


Show code >


You probably won't need it in your development environment, but notification about erros should be a part of you production application for sure. Let me just give a short example:
Pretty big portal. Maintained and upgraded all the time. Up to 1,5 milion page views per day. One of the popular pages that hasn't been touched for a long time was down because of some very low level code change... For 2 weeks. After I added notification about application errors, I was able to fix it immediately. Without it... Most probably it would still be down.

You can tell me that you are brilliant developer, that your sites have no problems, that when you create something you don't have to worry about it anymore. I can pretend that I believe you. Maybe even you are perfect. However remember that hardware and software that you depend on are not.



Shout it
Read More »

Posted on Saturday, January 24, 2009 by Marek Musielak

Intelligent custom 404 page

Have you ever clicked on the link on some page and got beautiful 404 page saying "Please make sure that you have typed the URL correctly"? Have you ever tried to open link that you found in google, the one that you had opened milion times before, and then saw the same page? I have. I know how annoying it can be. After all it is so easy to create custom 404 error page and display a message that is a little bit more intelligent.

Let's start with our own 404 page. Create new aspx file and call it whatever you want. PageNotFound is what I always use. I think it's good idea not to use the same template that we use for all the rest of our site - after all it is an error page. Pretty simple design, short message, maybe logo and few links with the most common used pages would be just fine. Now we need to set IIS to use this page for 404 errors instead of the default one. It's pretty simple. If you have never done this before take a look here http://technet.microsoft.com/en-us/library/bb727138.aspx. It will take you less than 5 minutes.

Ok, so we have custom error page, but what we were supposed to do was to display some intelligent message. That's the place where we can use url referrer. We can access it from code behind without any problems (Request.UrlReferrer). What does it give to us? In general we have 4 possibilities:

  1. Empty referrer. It means that user either typed the url and made a mistake, clicked on link sent by email of instant messenger or used a bookmark. This is what we can display to them: "Got a wrong link? Mis-typed the url? Your bookmarks are out of date?".
  2. Referrer is search engine. If referrer is from Google, Yahoo or any other search engine it is clear that index of this engine is most probably out of date. So tell user about it. We can even try harder. Several lines of code like those:

    Show code >

    give us information about what user looked for. Maybe we're able to give them a hint with few most probable links?
  3. If referrer is from some other site then we know that link on that site is incorrect. We're not able to do anything about this but we can always inform user that it's not our fault and that the link that they used is wrong.
  4. The last possibility is that referrer is from our site. It would be good to apologize and fix the link.

Yeah, fix the link ... Easy to say but ... we would have to know that we have a bad link somewhere on our site first. It is easier than you think. Let's send an email to us. Another piece of code will send a mail to our addresses with information on where user came from and what wasn't found:

Show code >

What is more, if many users try access the same not existing url (e.g. we change the url of one of the pages on our site), we can redirect them where they most probably wanted to be. I recommed using 301 redirect (permanently moved) instead of 302 (temporarily moved). I'm not going to draw water in a sieve trying to convience anyone of pros and cons of 301 redirect - if anyone is really interested in this, type 301 vs 302 in google. It's enough of this in the web already, let's do not create any artifical crowd ;)

Let's go further with 404. Our custom 404 page will inform us not only about not existing pages, but about the missing images, javascript files or even hacking attempts. If you will notice that some ips flood you with suspicious requests, you can always ban them. And if you are tired of getting and getting 404 emails that you are not interested in, you can always create a list of regexes and filter what do you want to send and what not.

Agree with me or not, but custom error pages for 404 or 500 errors should be one of the first steps in web application development.



Shout it
Read More »