Set Up Simple Browser Detection
Using CSS, you can apply different rules to iPhones and iPads to optimize how your site looks. You can alter how a page appears in landscape or portrait view, and you can hide certain parts of a page when viewed on specific devices.
Using CSS to target your designs is the simplest route, but when you take this approach, you’re still delivering the entire content of your page to each device, which means that you may make your audience download more content than necessary. This issue is especially problematic if visitors are viewing your pages over slow connections or if you include a lot of large image, video, or audio files.
You can use a relatively simple PHP script that delivers different content to an iPad than it does to an iPhone. This kind of script is useful if you want to block videos, images, or other types of content from being downloaded to an iPhone.
In the figure the Jelly Rancher contact page was used as an example. In this case, the PHP script delivers more content to the iPad than the iPhone because we removed the QR code and Microsoft tag in the right-sidebar before delivering the page to the iPhone.
The PHP code featured in this section provides a handy way to tailor the content delivered to an iPhone or iPad on a specific page. The contact page displays more information on the larger iPad screen than on the iPhone screen. In this example, a little PHP code was used to remove the second photo, as well as the QR code and Microsoft tag, from the contact page before the page is sent to an iPhone.
When you use PHP code in an HTML document, you must change the extension of the file from .html to .php. You can mix pages with .html and .php extensions in the same website.
The first step in being able to send only the data that each individual browser needs is to detect which browser is visiting the page. You can use any server-side language, such as Java, .Net, or PHP.
The PHP used in this example works fine for a simple example, but you’re better off with a more comprehensive device detection script.