When developing a site with a responsive CSS design, your site changes the way information is presented based off the client’s screen size. In many cases, smaller screen sizes mean that less information is displayed.
Lets say you have a site designed for the desktop. In your server-side code, you make several database queries and then on the pages you display that information in some form.
Now, lets say your CSS design in responsive and some information is not shown to devices with small screens. Lets say that some of that information is that is not shown is from database queries. What this means is that when a mobile device loads up this page, the server-side code is making unnecessary database calls because the resulting information isn’t going to be shown to the end user because of their screen size.
Responsive Design typically uses CSS media queries to determine what information is shown based off of device screen size. What is a good approach to writing effective and efficient server-side code for responsive designs?
Have you considered using AJAX to pass pass data about the screen size back to the server-side php? Then run queries based on the corresponding CSS design. Your problem comes in if you have mobile devices that don’t support JavaScript or browsers that disable it. You also have additional maintenance – if you change your CSS to display more or less, your scripts will have to be updated to stay in sync.
In general, I believe that CSS media queries are meant to be used to optimize the display of the content of various sizes but ignore the “losses” of content. This may mean that extra queries/calculations/content are loaded but hidden. The upside to this is that if your user is operating in a browser that is scaled down and then they maximize it, they get a fresh display of the full page. If they don’t have the full set of content, though, they won’t get to take full advantage of it unless they refresh the page.
I think you need to ask yourself – is the extra build and maintenance effort on your part worth saving some queries on the backend?