It is not possible to get true TTFB in JS since the page only gets the JS context after the first byte has been received. The closest you can get is something like the following:
<script type="text/javascript">var startTime = (new Date()).getTime()</script>
very early in the <head> . Then, depending on whether you want to check whether the html ends or the download ends, you can put a similar tag at the bottom of the html page (and subtract the values) and then make XHR back to the server (or set a cookie that you can get on the server side the next time the page is requested) or listen for the onload and do the same.
Stuart k
source share