Can we load PHP includes based on device-width?

There’s a lot of talk about loading web assets based on device width or screen size. That is, load full content for desktop browsers over 640px, but alternate content for devices with screens of 640px or smaller.

Right now in HTML, if a person visits a web site designed for large and small screens, the smaller device will still download the larger site’s version (larger imgs and Javascripts for large screens), then the smaller images (and leaving out the large JS code) for the smaller device.

Is is possible to programmatically load certain includes in PHP, perhaps based on device-width media queries? That way, small devices would never load the full-size content in the first place, resulting in a faster download. If so, can someone give an example of PHP code executing depending on device width?

Thanks!

Not by width but by the http headers. The http headers is your *best bet when it comes to determining a device that is in usage on the server-side without separate domains. Searches fo google for “inspecting http header for mobile device” should reveal some actual implementations.

Very good, thanks!

I found this site: http://www.justindocanto.com/scripts/detect-a-user-on-a-mobile-browser-or-device

That looks like it would work. Kinda sloppy but simple. So should be fine.

usually from php not possible. in this case you have to make ajax call or redirect request to invoke right php.