0

Using Django, is it possible to check if a user has a high resolution device? Server side.

I know it's possible with CSS media queries like so:

@media 
only screen and (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
}

But I need to know which version of an image (normal or 2x res) to display before the page loads.

Thanks in advance!

amba88
  • 759
  • 3
  • 9
  • 27
  • `var retina = window.devicePixelRatio > 1;` in Javascript tells you if display is retina. Now, inject the device type from client to server. – karthikr Oct 21 '13 at 20:38
  • This can only be set after they've loaded at least one page on the site. So it will work, just not for the initial page load. Plus you'll want to put this information in a cookie or in the Session. – Fernker Oct 21 '13 at 20:41
  • Possible duplicate of [detect retina display in PHP](http://stackoverflow.com/questions/15234519/detect-retina-display-in-php) – rogerdpack May 02 '17 at 15:21

2 Answers2

0

Possibly.

If you mean from the basic request headers from the client, then no there isn't a way. But there are some other ways involving setting a cookie with client information that you then send in future requests and can use in your templates.

I haven't ever come across a solution for Django, but have seen various ones for PHP that could probably be ported to Django. But you'll want to do some digging to see if it fits your needs.

Fernker
  • 2,238
  • 20
  • 31
0

Based on what people have said I've decided the best course of action would be to check via Javascript as soon as the page loads and replace the image URLs.

Thanks for your answers :)

amba88
  • 759
  • 3
  • 9
  • 27