简体   繁体   English

媒体查询:避免不必要的CSS /图像下载

[英]Media queries: avoiding unnecessary downloading of CSS/images

I've been reading about the 'only' keyword but can't find a definitive answer to this. 我一直在阅读有关'only'关键字的信息,但找不到确切的答案。

I'm interested to know if there's a way, using only CSS (not Javascript), to avoid all older browsers that don't understand media queries (eg old mobiles) and modern browsers that do understand media queries but that return false for them (eg smartphones looking at min-device-width of 740px) reading linked CSS files and downloading associated large background images. 我想知道是否有办法仅使用CSS(而不是Javascript)来避免所有不了解媒体查询的旧版浏览器(例如,旧手机)和能够理解媒体查询但返回假值的现代浏览器(例如,智能手机查看的最小设备宽度为740px)读取链接的CSS文件并下载相关的大型背景图片。 I'm concerned about loading times and bandwidth. 我担心加载时间和带宽。

If this isn't possible, I'm thinking I'll use http://www.handsetdetection.com/features/mobile-browser-detection or http://www.hand-interactive.com/resources/detect-mobile-php.htm (server side solutions) to conditionally serve "full fat" stylesheets that contain perhaps larger images only to device widths of 740px and above, for example. 如果无法做到这一点,我想我将使用http://www.handsetdetection.com/features/mobile-browser-detectionhttp://www.hand-interactive.com/resources/detect-mobile -php.htm (服务器端解决方案)有条件地提供“全脂”样式表,例如,该样式表可能包含较大的图像,但仅适用于设备宽度为740px及以上。

I'm pretty sure you either have to use server side script for detection, or javascript. 我很确定您必须使用服务器端脚本进行检测或使用javascript。 But if you do server side, you can display out your own style sheets according to what you do or don't want. 但是,如果您在服务器端工作,则可以根据您想要或不想要的内容显示自己的样式表。

http://code.google.com/p/php-mobile-detect/ http://code.google.com/p/php-mobile-detect/

That might be good place to start for php prebuilt library. 那可能是开始使用php预建库的好地方。

Server side would be my suggestion. 服务器端将是我的建议。 You could also use a cookie to store data for the remainder of the session and potentially if the user returns. 您还可以使用Cookie来存储会话剩余时间以及用户返回时的数据。 Store something like whether or not visitors want to see the mobile or full version. 存储诸如访客是否要查看移动版或完整版之类的内容。 You can test it at the apache level in .htaccess to make it extremely efficient. 您可以在.htaccess中的apache级别对其进行测试,以使其效率极高。

Mobile Redirection is Platform Independent 移动重定向与平台无关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM