Zend certified PHP/Magento developer

User Agent being cached and returning incorrect details

We are trying to identify mobile devices to serve mobile specific images for speed optimisation.

When requesting the User Agent on our homepage, it will return the correct agent when placed in one area on the page, and when placed in another the User Agent gets cached and never changes.

Is this normal behaviour? Or has our theme somehow disabled/enabled page cache where it shouldn’t be?

Screenshot and mark-ups below.

I know a bit about Magento 2 but not advanced. We have a developer working on our site but he can’t get this working.

Thanks! enter image description here