Can a Worker access client's screen size?


I use a Worker to implement HTTP/2 push for CSS assets. I have two CSS files: the normal one and another with the responsive queries. It would be awesome if I can detect the client’s screen size so that the Worker can push the appropriate CSS file.

Is it possible to do that with Workers?

By the way, I know that a Worker can inspect the user agent string. But that’s not a solution for me given that it’s error prone, can give false positives, and need regular updating and maintenance.


CF Workers run on the server-side not client-side, so they don’t have access to device info.

In general, unless your responsive and non-responsive css is extremely different, it’s better to push css with the responsive queries always. Don’t over-optimize a couple KB.

If they are extremely different, then you are down to user-agent parsing which is more reliable than people make it out to be. If someone is faking a user agent, then they shouldn’t be surprised to get a different site. (Though, I will point out our mobile detection is rather more complicated than the average if/else script)


Thanks for the reply and input. My responsive CSS file is around 1KB (minified and gzipped), so it looks like I fell into the trap of wanting optimize a problem I don’t have. :slight_smile:

I’ll just merge the CSS in one file as you suggested.