简体   繁体   English

如何检查网站的移动版本?

[英]how to check for mobile version of a website?

I would like to check if mobile version exists for a specific website or not. 我想检查特定网站是否存在移动版本。 To my understanding, we cannot be sure if every website has mobile version located at http://m.example.com/ therefore I am testing through CURL() request. 据我了解,我们无法确定每个网站的移动版本是否都位于http://m.example.com/上,因此我正在通过CURL()请求进行测试。 Here is how I am doing it: 这是我的做法:

* I send mobile browser headers in curl request, this returns contents of 
the returning URL. 
* If it has a mobile version, then it would return contents of a mobile version site.
* I then check if the content includes @media keyword, if it exists then I assume it has a mobile version.

The problem is, if its css loads externally then I will have to further send CURL() requests to the CSS files as well, which will make it even more slower. 问题是,如果它的css从外部加载,那么我将不得不进一步将CURL()请求发送到CSS文件,这将使其变得更慢。 Is there any specific solution to my problem or can I boost this process a bit more? 有没有针对我的问题的特定解决方案,或者我可以进一步提高这个过程?

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

The problem with your approach, which smells a bit like an XY Problem , is that it is simply unreliable. 您的方法存在的问题(有点像XY问题)是根本不可靠。

The website has many choices for mobile websites, which include: 对于移动网站,该网站有很多选择,包括:

1. Using CSS media queries 1.使用CSS媒体查询

The problem with this method is twofold. 这种方法的问题是双重的。 For starters, you would have to scan every single CSS file and <link> declaration. 对于初学者,您将必须扫描每个CSS文件和<link>声明。 Secondly, the site can dynamically introduce stylesheets to the page using JavaScript, which you will never see using cURL because it lacks a JavaScript parser. 其次,该站点可以使用JavaScript动态将样式表引入页面,因为cURL缺少JavaScript解析器,因此您永远不会使用cURL。

2. Browser sniffing using (client side) JavaScript, or screen width sniffing using JavaScript 2.使用(客户端)JavaScript进行浏览器嗅探,或使用JavaScript进行屏幕宽度嗅探

Again, this JavaScript will never get executed, so you will never see that result. 同样,此JavaScript将永远不会执行,因此您将永远不会看到该结果。

3. Browser sniffing using server side code 3.使用服务器端代码进行浏览器嗅探

Well, I guess you could try to use a mobile user-agent string with your cURL request, and see where that takes you, but all of these methods are hackish and unreliable. 好吧,我想您可以尝试在cURL请求中使用移动用户代理字符串,并查看将您带到何处,但是所有这些方法都是骇人听闻且不可靠的。

4. The page could be mobile friendly from the get-go (credit to @Quentin) 4.页面从一开始就可以移动友好(贷记到@Quentin)

As @Quentin mentioned in the comments, the page could be mobile friendly without any additional checks on the client/server side (responsive design without media queries, by simply using percentage-based values, for example). 正如@Quentin在评论中提到的那样,该页面可以是移动友好的,而无需在客户端/服务器端进行任何其他检查(例如,不使用媒体查询的响应式设计,只需使用基于百分比的值即可)。

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

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