0

I use two <img> tags to calculate page load time.

The server returns a 1x1 pixel image and tracks the two timestamps when the request got fired and the difference between them gives me the page load time.

One <img> tag is just after the beginning of <body> tag and other just before the ending of </body> tag.

But the problem is many a times I get the 2nd <img> tag fired first and then the 1st <img> tag.

Can anyone tell me how this happens and how do I resolve this? Are the requests sent in parallel?

NOTE: If I am following the wrong approach, please mention an alternative to this but do not mention tools such as google analytics etc.

Antara Roy
  • 475
  • 1
  • 7
  • 14
  • 1
    You are following a wrong approach. The browser is free to load page resources in any order it chooses. – JJJ Dec 31 '14 at 10:09
  • @Juhana Can you provide a link in support of your answer above? And can u give me an alternative solution? – Antara Roy Dec 31 '14 at 10:18

1 Answers1

0

straight from the answer -- It's possible to some extent but won't be really accurate, the idea is load image with a known file size then in its onload event measure how much time passed until that event was triggered, and divide this time in the image file size.

you can check this answer https://stackoverflow.com/a/5529841 this worked for me

Community
  • 1
  • 1
ARIF MAHMUD RANA
  • 5,026
  • 3
  • 31
  • 58
  • Actually i have to support low-end mobile phones which doesn't support javascript. So I went for this approach of mine and tracked the loadtime in the back-end. – Antara Roy Dec 31 '14 at 10:32
  • Strange. I think if you want to support a mobile phones which doesn't have a js support almost all your effort will be a dice play. You can try the same trick with 'link' or 'script' tag. – Sarath Dec 31 '14 at 14:42
  • The question states "WITHOUT JAVASCRIPT", when you need to resort to an event, you need event listener, and so javascript – Wax Mar 20 '20 at 19:59