Over time I noticed a browser behavior that I slowly learned to hate.
I can figure it was implemented with all the best intentions, but as we all know .. hell is paved with good intentions.
Here's my pet peeve: most browser will request /favicon.ico upon all request on any site even though the site has either no favicon specified or a favicon with a different path.
So if you're using django like me and put your favicon where it belongs, in /media/img/, you might get irritated to see this over and over:
"GET /favicon.ico HTTP/1.1" 404 2028
Fortunately the solution is quite easy, it's only a matter of returning the proper middle finger to the client:
(r'^favicon.ico$', 'django.views.generic.simple.redirect_to', {
'url': '/media/img/favicon.ico', 'permanent': True, }),
"GET /media/img/favicon.ico HTTP/1.1" 200 15086
One resource, one (successful) request. Me happy.
That said, I think it's somewhat bad because it goes against everything we learned about HTML. Web browser should fetch only the resources they are asked to fetch in order to ensure a predictable behavior.
Am I crazy or what ?
Using link rel=icon on your page you can direct the browsers to the right file. So yes, you're crazy. A large part of the web is built on hacks. Bots browsing your site to build search machine indexes. Browsers that do all kind of weird things to implement some feature that the designers of the web never dreamt of. It's just the way it is.
The only problem with this is that it causes an extra hit to Django, which may not be desired.
There are two other ways around it that don't require going through Django.
Alias /favicon.ico "/media/img/favicon.ico"
You didn't get my point at all. What if I don't want a favicon ? I get a 404 hit anyway, it shouldn't be like this.
What the fuck are you talking about ? I'm talking about a very specific browser behavior and you talk about crawlers ? What's the point ?
And FYI:
I AM NOT CRAZY. (thanks to a random guy on reddit for the link.)