I\'ve always wondered whether whitespace before a DOCTYPE matters, but I can\'t seem to find any definitive information on the web. People say not to do it,
No, the Doctype doesn't have to be the first line of the file but it does have to come before the tag. That is the only limit you have, so your first method to do it is fine.
The declaration must be the very first thing in your HTML document, before the tag.