I noticed this morning that some of my older posts were getting crazy out of hand with their referrer lists. Some of them, even compressed with GZIP, were spitting out over 300k of content. That’s stupid!
So, in order to speed things up for regular browsers of my blog, I hacked a bit of the just-released version of DasBlog, specifically in the newtelligence.DasBlog.Web.Core project, the Macros.cs file… adding this code around line 3130:
1: if (requestPage.Request.UserAgent != null)
2: {
3: if ((trk.PermaLink.IndexOf("q=") > -1 | trk.PermaLink.IndexOf("p=") > -1) &
4: (requestPage.Request.UserAgent.Contains("Googlebot") |
5: requestPage.Request.UserAgent.Contains("Yahoo! Slurp") |
6: requestPage.Request.UserAgent.Contains("Yahoo-Blogs") |
7: requestPage.Request.UserAgent.Contains("Ask Jeeves") |
8: requestPage.Request.UserAgent.Contains("BecomeBot") |
9: requestPage.Request.UserAgent.Contains("msnbot")))
10: {
11: // Let it happen.
12: }
13: else
14: {
15: continue;
16: }
17: }
This will see if the user-agent matches a common bot’s, and if it does, allows the code to continue building up the referrals list. Otherwise, it skips through them all and is completely empty.
But at the end of the loop, you need to check for the item count to be 0. If it’s zero, we know that we have no referrers to show, so we need to clear out the placeholder’s content (since it will contain an empty “Referred By:“ literal control:
1: if (count == 0)
2: {
3: placeHolder.Controls.Clear();
4: }
And there you have it, you’ve hacked DasBlog.
Update: Don’t listen to me. This is what Google calls “cloaking” and it’s a sure fire way to kill your pages (and get them thrown into Google’s “supplemental index”.) This is really lame. Yet Google themselves does “cloaking”. Seems a bit hipocritical.
As it stands right now, a majority of my blog’s search results are in the supplemental index now, probably because of my hack. And there’s no way I’m turning referrers back on (the pirates of the caribbean 3 blog entry I wrote is almost 600K gzip’d to the client because of all the referrers) — so I’ve turned referrers off completely. My loss, I guess.