2011-09-30

Multiple identical html page requests issue

If you have noticed your browser is doing multiple identical requests to load a single html page, chances are you have run into the same issue, empty string url in html. In my case, it was empty css reference:
    <link href="" rel="stylesheet" type="text/css"></link>
I consider myself lucky that it took just a couple of hours to figure out what is going on. Seriously, this could have gone a lot worse.

Here is my story. I noticed that one page was taking a little longer than it should to load. Sure, it may be Amazon's EC2 micro instance not having enough steam, considering the page was a bit heavy both computationally and by size. Still, I fired up Fiddler, and of course was a bit surprised to see that the page has been requested twice. I browsed to some other pages on that website, and Chrome was constantly issuing two apparently identical requests for a single page. Switched to IE9 - all OK. Opera - OK too. So this must be issue with Chrome. Maybe it is optimizing browsing experience, and when response doesn't arrive in timely manner, it retries, I thought. And indeed, I managed to find different traces of information that Chrome might be doing something like that; however, there was nothing authoritative. And by the way, why is it doing this to all pages, even those with sub-0.1s response? Now some really strange ideas start creeping into my mind. Maybe Chrome on my PC has decided that this particular website doesn't respond in timely manner and now has created behavior model for it - request every page twice? (yeah, I must be crazy) Check from my laptop - nope, the same issue. Then it comes to my attention that the second request is issued not immediately, perhaps after the first request got response? Checking timings with Fiddler confirms that this must be the case. Now then the last thing to notice -second request is a little bit different from first one, it has this header:
Accept: text/css,*/*;q=0.1
I take a look at my master template, and there it is, empty link css, a product of my hand-rolled css/js minimization solution. Yet another time I regret having opted for homemade stuff. Gotta go look at SquishIt once again.