大网数据广告活动
网站运营与故障问答

Embedded YouTube videos make my site fail Google's mobile optimization tests

· 52CE 我爱测

I have a website with a responsive theme optimized for mobile. Despite that, many pages don't pass the "mobile-friendly test" from Google ( https://search.google.com/test/mobile-friendly ) Here is the result of the validation att…

问题原文

原帖链接 · Sifro · CC BY-SA 4.0

I have a website with a responsive theme optimized for mobile.

Despite that, many pages don't pass the "mobile-friendly test" from Google (https://search.google.com/test/mobile-friendly)

Here is the result of the validation attempt on Google's tool:

(the reasons why the validation fail are: text too small; clickable elements too close to each other)

I've found out that all the pages of my site unable to pass this test contain an embedded YouTube video.

If I remove the video, each of these pages passes the test.

The video is added with the following code:

 <div class="video-container">
     <iframe width="853" height="480" src="https://www.youtube.com/embed/UbtGFrUpri4"
     frameborder="0" allowfullscreen></iframe>
 </div>

The CSS is:

.video-container {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
}

.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

The video scales responsively on my mobile device.

My question is: is there a way to have my page mobile-friendly embedding a YouTube video?

Also I would be curious to know whether it's normal that Googlebot doesn't parse CSS and JS, and shows the "your browser doesn't support this feature" snippet instead of the video.

已采纳解答

原帖链接 · Sifro · CC BY-SA 4.0

Ok, this was tricky because Google's suggestions are deceitful: Google talks about "clickable elements too close to each other" and "small text", but looking at the screenshot, the problem is that the video container is too big (despite the responsive wrapper).

Considering that there's an error type in the tool called "content bigger than the screen", I have no idea why Google didn't make this case fall into this category.

Anyway, forget about small text, forget about the fact that the actual video is scaling responsively on any actual mobile phone: Googlebot will see a large iframe going off-screen, marking your site mobile-unfriendly.

The only solution I found was to remove the width and height attribute in the HTML code of the iframe. In other words, you have to alter the normal youtube embedding code that will now look like this:

 <iframe src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0" allowfullscreen>
 </iframe>

This lets me pass the mobile friendly test on all the offending pages.

Hopefully, the removal of the height and width attributes won't create any problems to the normal output of the video for normal browsers.

Let me know if you have a better solution or think it could cause any issues.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2019-11-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。