Determine screen size and pixel density on server side?

I am doing some research, and I think I already know the answer, but I wonder if there are any means by which you can get the screen size and pixel density without using javascript or rely on CSS3 environment requests.

In essence, I’m studying what it takes to get screen resolution and pixel density so that the server can decide which image on the server is in the URI request.

So far, I have not found anything that says it is possible, but I thought hey, why not ask?

+6
source share
4 answers

Ruby works on the server side - without receiving information from the client, it does not have the opportunity to find out any client features.

0
source

I do not completely agree with the correct rule. In reality, this answer is true in many cases ... but theoretically, this is not so. Often, requests made to the web server contain a User-Agent field, which theoretically can be used to recognize information about the resolutions and properties of the device screen.

Web requests do not first go through the client. They go to the server, which then serves the page for the client, so the server first receives the request ... Ruby on Rails, for example, receives the request through the action controller to the resource and then serves the page for response.

See an example UA analyzer, for example: https://github.com/visionmedia/user-agent

An example user agent sent by my computer:

User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like enter code here`Gecko) Chrome/17.0.963.83 Safari/535.11 

I think it is extremely possible to well understand that my screen resolution (DPI, etc.) is provided by this information through the server. Of course, you'll need a device information table for reference.

For mobile devices, this is even easier. If the User-Agent is Mobile Safari for iPad:

  Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10 

You can know with confidence what the screen resolution on the server is. You can even find out the height and width of the browser with this information. I suspect this is true for many mobile devices, such as Android or Win Mo.

So, summing up, I agree that this is inappropriate to do, but I also disagree.

I believe that Facebook took over the basic devices for cataloging projects and screen resolution and made it open source because they had similar problems when creating a facebook mobile application, for example. they had to catalog all the inconsistencies between all mobile browsers so that they could adapt the client application to each individual case. Perhaps this project may have the necessary information for this ... theoretically.

+9
source

For something impossible, it looks like Mobvious is doing a decent job:

Mobvious determines if your application / website will be a phone, tablet or personal computer. Then you can use this information throughout the application. (For example, for your foreground code regarding the type of device. There is a plugin for Ruby on Rails to help you with this.)

https://github.com/jistr/mobvious

+2
source

You can use Ahoy . The current_visit method contains the following information.

When someone visits your site, Ahoy creates a visit with lots of useful information.

traffic source - referrer, referring domain, landing page, search
location of keywords - country, region and city technologies - browser, OS, and device type
Utm parameters - source, environment, term, content, campaign

0
source

Source: https://habr.com/ru/post/898279/


All Articles