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

1 Answer 1


If you want to access the user-agent in the template to identify the device you will have to turn off FPC. This will significantly degrade customer experience and will likely result in lowered conversion, sales and increased page load time, pushing customers to your competitors. If you want to send device-specific optimised images to customers devices I would suggest implementing a CDN with built-in image optimisation such as https://www.fastly.com/

  • Hi Craig, thanks for the answer!
    – Matt R
    Apr 24 at 23:27
  • Hi Craig, thanks for the answer! The user-agent is returning the correct details in some areas on the homepage, and also on the category pages. If we output the user-agent via Magento_Catalog/templates/product/list.phtml it works correct every time. Does this mean our site may have a caching issue, or is it normal for some pages such as list.phtml to not load from cache?
    – Matt R
    Apr 24 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.