In my joomla website, I have a module that outputs 1 item by default, in its help.php file, there is something like
$items = 1;
$db->setQuery($query, 0, $items)
Now I want to detect if users' screen width is less than a certain value, if yes, then get only 1 item, else get 4 items. What is the best practice to do it?
I can just set $items to 4 and use javascript to eliminate the other 3 items, but this is not a perfect solution because excessive data will be downloaded. My questions are: 1) can PHP alone detect client's screen width? 2) If no and I have to use javascript/ajax, I am thinking add
<script>
var w = screen.width;
href = location.href;
if (location.search){
href = href + '&screenWidth=' + w;
} else
href = href + '?screenWidth=' + w;
</script>
to every page and use $_GET['screenWidth]
to get the screen width value in the helper.php file, is this a good practice? Is this gonna mess up with output buffer sif there is any) set by my CMS(joomla)?