看看这个 PHP 类。由于您的页面已被解析并从您的服务器完整发送到桌面,因此您的 PHP 可以过滤出移动设备是否正在查看该页面并阻止发送不需要的代码(以及随后通过该代码加载的对象 - 例如图像)。
此页面有一组很好的示例/用例,让您了解如何构建代码。
PHP 真实世界示例
<?php
include 'Mobile_Detect.php';
$device = new Mobile_Detect;
if ($device->isMobile()) {
$images = FALSE;
}
?>
^这是在所有页面访问的包含文件中
<article>
<header>
<section id="author-name">
<?php print $author_name ?>
</section>
<section id="author-img">
<?php if($images): ?><img src="http://example.com/image.jpg" /><? endif; ?>
</section>
</header>
<content class="article">
<?php if($images): ?><img src="http://example.com/article1.png" class="article" /><? endif; ?>
<h2 class="title article">Article Title</h2>
<p class="content article">Blah blah blah blah blah article stuff</p>
</content>
</article>