How to use nofollow link in script tag [duplicate]

丶灬走出姿态 提交于 2019-12-14 04:05:34

问题


This is my script code:

<script type="text/javascript" src="//example.com/js/infolinks_main.js"></script>

I want to make crawler not to follow or index example.com/js/infolinks_main.js.

How can I do this task? I have robots.txt in my root, but that URL is an external URL.

NB: I do not want to use iframe.


回答1:


The script element can’t have a rel attribute, so nofollow can’t be used. Even if it could be used, note that nofollow is not about disallowing bots to crawl/index the URL.

To disallow crawling the script, you have to use robots.txt:

User-agent: *
Disallow: /js/infolinks_main.js

Or if you want to disallow crawling of all your scripts:

User-agent: *
Disallow: /js/

You have to use the robots.txt file of the host where the scripts are hosted. It doesn’t necessarily have to be the host where your HTML documents are hosted.

(Note that this doesn’t disallow indexing the script. If you want to disallow indexing, you can use the X-Robots-Tag header with a noindex value, but then you have to allow crawling. As scripts are typically not indexed by general-purpose search engines, you probably want to prevent crawling, not indexing.)




回答2:


rel=nofollow only applies to hyperlinks, there's no point in adding it to any other kind of element.

If your scripts create links, you could edit the script to ensure that they do so with a rel=nofollow attribute; but given that the google bot does not execute scripts when reading a page, there's no real point in doing so.



来源:https://stackoverflow.com/questions/47346760/how-to-use-nofollow-link-in-script-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!