If you have received one of the many warnings Google sent out about “Googlebot cannot access CSS and JS files” in your Google Search Console, there has been much confusion about how to ensure you are allowing Googlebot to crawl these blocked resources without potentially opening yourself up to security issues, as the commonly blocked parts of WordPress – /wp-admin/ and /wp-content/plugins – are triggering the warnings, depending on how WordPress and various plugins are set up.
Fortunately, there is an easy way to allow Googlebot to crawl all CSS and JavaScript files while still allowing other areas to remain blocked.
Simply add the following to your robots.txt and it will allow Googlebot to crawl all the CSS and JavaScript files on your site.
User-Agent: Googlebot Allow: .js Allow: .css
Also remember that Google does not index .css and .js in their search results, so you do not need to worry about these files causing any unnecessary SEO issues. In fact, the opposite will happen since blocking .css and .js files “can result in suboptimal rankings.”
Once you add this, you can confirm using the Google Search Console “Fetch as Google” to ensure the resources were successfully unblocked with the new robots.txt file.
While some commenters pointed out a similar robots.txt in comments here, Gary Illyes from Google confirmed the use of this in robots.txt at stackoverflow.
…the simplest form of allow rule to allow crawling javascript and css resources:
User-Agent: Googlebot Allow: .js Allow: .css
This will allow anything like
https://example.com/deep/style.css?something=1
orhttps://example.com/deep/javascript.js
, and leaves no much space for interpretation for other search engines.Once you have this, you can test your setup in Search Console – Blocked resources feature.
We have more details on the “Googlebot cannot access CSS and JS files” warning here, and here are instructions so you can find exactly which resources Google thinks you are blocking, even if you are certain it is a false positive (it probably isn’t).
Jennifer Slegg
Latest posts by Jennifer Slegg (see all)
- 2022 Update for Google Quality Rater Guidelines – Big YMYL Updates - August 1, 2022
- Google Quality Rater Guidelines: The Low Quality 2021 Update - October 19, 2021
- Rethinking Affiliate Sites With Google’s Product Review Update - April 23, 2021
- New Google Quality Rater Guidelines, Update Adds Emphasis on Needs Met - October 16, 2020
- Google Updates Experiment Statistics for Quality Raters - October 6, 2020
Arun says
Yes, this is mandate now and it seems google has revamped its algorithm of ranking with the JS and CSS usability as prime factor.
I have received for all most all the clients having the wordpress where i blocked the access to wp-include through robots file.
Sandip Paul says
Thanks a lot. This help a lot …
Uzma Shahzadi says
I think the solution is incomplete. Directives mentioned in this article are not complete. Only “Allow: .js” will allow only those “.js” file that are at root level.
To allow all the “.js” and “.css” files, the wild card operator (*) is required. See the code below;
User-Agent: Googlebot
Allow: *.js
Allow: *.css
Ahmad Ali says
Uzma that’s really good answer I agree with you.
Casey Markee says
Yes, the solution referenced in this article is INCORRECT. You must have the “wildcard” command in the lines for this to work.
This is correct:
User-Agent: Googlebot
Allow: *.js
Allow: *.css
This is NOT correct:
User-Agent: Googlebot
Allow: .js
Allow: .css
Make sure to include this at the top of the robots file since commands are read from top to bottom.
Yoast has published a great new resource stating that you should also be removing (unblocking) access to /wp-admin/ as well.
That’s a must-read and you can find that resource here (read the comments as well).
https://yoast.com/dont-block-your-css-and-js-files/
Andrea says
The suggestion is definitely wrong cause it doesn’t cover every case.
Apart from that suggesting a predefined robots.txt is never a good idea.
Never disallow anything except if you know what you are doing and after looking your server log files.
johnsmith007 says
If you have wordpress website then should need to edit like first go your wordpress dashboard
and choose seo section and click on edit files and
default code like
User-agent: *
Disallow: /wp-admin/
insert new text below this code like
User-Agent: Googlebot
Allow: *.js
Allow: *.css