Googlebot 无法访问 CSS 和 JS 文件?

Googlebot cannot access CSS and JS files?

收到 Google Search Console 警告 - "Googlebot cannot access CSS and JS"

我的robots.txt

User-agent: *
Disallow: /_System
Disallow: /bcas-homepage-slider
Disallow: /css
Disallow: /fonts
Disallow: /images
Disallow: /js
Disallow: /Layouts
Disallow: /Medigap logos
Disallow: /POST-IMAGES
Disallow: /products
Disallow: /professional-specialities
Disallow: /_backups
Disallow: /thank-you
Disallow: /stylesheets
Disallow: /source
Disallow: /Report
Disallow: /new

如何删除这个警告?

您需要编辑位于站点根目录的 robots.txt 文件。 只要有 "Disallow" 行,就意味着您要求 google 机器人不要爬过这些目录。

只需要从 robots.txt

中删除以下内容
Disallow: /css
Disallow: /js

早在 2015 年 4 月,我根据当时随 Joomla 3.x 分发的更新 robots.txt 文件修改了我的 robots.txt 文件,以便删除以下行:

Disallow: /media/
Disallow: /templates/

Google 发出了新一轮的警告消息,似乎需要更多访问权限。

准确查看需要取消阻止的内容的最佳方法是登录网站管理员工具(又名 "Search Console")并转到 Google 索引 -> 已阻止的资源。这假定您的网站已启用 Search Console。

看起来 Google 希望我现在取消阻止以下包含 CSS 和 JS 资源的文件夹:

Disallow: /components/
Disallow: /libraries/
Disallow: /modules/
Disallow: /plugins/

您的里程可能会有所不同。

对于 Joomla 3,这可能是最简单的解决方案。将其添加到默认 robots.txt 文件的末尾。

#Googlebot
User-agent: Googlebot
Allow: *.css
Allow: *.js

如果您想更具体一点,请使用以下内容:

User-agent: Googlebot
Allow: /plugins/ *.css
Allow: /plugins/*.js
Allow: /modules/ *.css
Allow: /modules/*.js

More on that

"Googlebot Cannot Access CSS and JS Files" 问题的综合解决方案,描述 here

What does the message mean?

This message is all about Google's new focus on responsive design.

Your robots.txt file is telling Google not to use some of your CSS and/or Javascript files.

Google now needs these files to test your site for mobile friendliness. Without them, your ranking will go down. We covered almost exactly the same problem back in April during Google's "Mobile Armageddon".

What is the solution?

Go to Google's Mobile-Friendly Test and check your site. Here's a screenshot of a site that's received Google's e-mail.

Thankfully, Google's tester is very informative and points out the exact issue for this particular site. It's that the robots.txt file is blocking Google from accessing the resources it needs.

You can find the exact resources that are blocked by Google by clicking on the "Show resources" link on the right-hand-side of Google's tester Compare the files there to your robots.txt to determine what needs unblocking.

How to fix the problem

The solution will depend on the CMS you use, because each platform stores CSS and Javascript files in different locations.