This is because browsers parse the DOM and do not store HTML in memory. What is returned to you is the conversion of the browser of the current DOM back to HTML, which is the reason for the header tags and the absence of closing tags, where applicable.
XMLHttpRequest is best suited. In most cases, assuming the server does not send the header without a cache, and the HTML page has finished loading, XMLHttpRequest will be almost instantaneous because the file is being fetched from the cache.
source share