Hints for web-developers

This is a brief list of things I picked up while listening to the Stackoverflow Postcat #38:

1. Create a subdomain for serving images. Reason: A web browser usually only makes a  maximum of two simultanious connections to a single domain. So if you move your images to a different domain, e.g. images.yourdomain.com, the browser makes more than two connections and downloads your site faster. As you see a subdomain is enough to do the trick.

2. Since web browser do very aggresiv caching of css files it happens that a web browser doesn’t pick up your updated css file until the user manually forces a refresh. A sulution is to add a version number to the name of your css file, e.g. style.css?3110. You can easily automate this task by using your current subversion revision number. This way you can force your client web browsers to use the latest css file.

3. Add a content-expires header to things like images to stop the web browser making even an request, to check if the ressource has changed. This minimizes the amount of http request needed to open your website.

There is a lot more to say to each of this points I guess, but it should serve as a reminder for me.

Cool video with Jeff Atwood

Just found this video of a presentation with Jeff Atwood and Phil Haack. Phil Haak gives an introduction on ASP.NET MVC and builds a simple Stackoverflow clone. But the real interesting part is when Jeff Atwood enters the stage and talks about Stackoverflow which is built with ASP.NET MVC. He logs in to the live server and shows some real Stackoverflow code. Don’t miss this.

Jeff Atwood presenting Stackoverflow
Jeff Atwood presenting Stackoverflow

How to benchmark queries on Sql Server

Recently I had to optimize some SQL-queries on Sql Server 2005. Therefore I used  Sql Server Management Studio.
I run into the following two problems:

  1. The resolution of the timer is one second. Thats too inaccurate.
  2. The cache in Sql Server optimized subsequent runs of the same query. So i couldn’t tell if I improved the query or made it worse.

If found the following solution for both problems on http://www.sqlnewsgroups.net/group/microsoft.public.sqlserver.server/topic13664.aspx. Just insert the query you want to tune below the comment and you can run your query always under the same preconditions.

DECLARE @Started datetime, @Ended datetime

— insert query to tune here

SELECT DATEDIFF(ms, @Started, @Ended)

DVD drive not visible in Vista

Recently my DVD drive on my Vista machine was not visible any more. The device-manager told me that the driver could not be loaded. I had no idea what the reason was. However this is the solution I found on the net:

  1. Open regedit
  2. Navigate to HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlClass {4D36E965-E325-11CE-BFC1-08002BE10318}
  3. Delete all keys named “UpperFilters” and “LowerFilters”


How to http post raw data in php

This example shows how to post raw data over http in php. For exemple if you want to send an XML-document to a web service.

$xmlData = ‘…’;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ‘http://example.com/service.php’);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-Type: application/xml”));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xmlData);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($curl);
curl_close ($curl);

The variable $response now contains the server response.

Hello, world!

So this is my new blog. My first blog. One of the main reasons for starting this blog is for me to have a database for all kinds of information that I may need again some day. Let’s see what comes…

Btw, although I am not an native english speaker I have planned to write my posts in english. Hope this helps to improve my english language skills. This is one of the other things I’m interested in.