Could this instead be this?
while (position < length - "</head>".length)
It would save 5 comparisons, which I usually wouldn't worry about but it seems you've identified this as a problem area.