我什么时候应该使用或避免子域?
最近,一位用户告诉我尽可能避免使用子域。 我记得读过谷歌将子域名视为一个独特的网站(这是真的吗?)。 当我使用子域时还会发生什么?什么时候应该使用或不应该使用子域?
我听说cookies不在子域之间共享? 我知道 2 个图像可以同时从一个站点进行 DL。 如果我使用 sub1.mysite.com 和 sub2.mysite.com,我可以使用 DL 4 吗?
我还应该知道什么?
Recently a user told me to avoid subdomains when i can. I remember reading google consider subdomains as a unique site (is this true?). What else happens when i use a subdomain and when should i use or should not use a subdomain?
I heard cookies are not shared between subdomains? i know 2 images can be DL simultaneously from a site. Would i be able to DL 4 if i use sub1.mysite.com and sub2.mysite.com?
What else should i know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在 Cookie 中设置了正确的参数,您可以在子域之间共享 Cookie。 但默认情况下,它们不会被共享。
是的,如果您将图像存储在不同的子域中,您可以获得更多的同时下载。 然而,天平的另一面是用户花费更多时间解析 DNS,因此拥有 25 个子域来同时获得 50 个下载是不切实际的。
子域发生的另一件事是,如果不付出一些努力,AJAX 请求将无法工作(您可以使用 document.domain 技巧让它们工作,但这远非简单)。
然而,尽管有些人不鼓励让 yoursite.com 和 www.yoursite.com 工作并返回相同的内容,但对 SEO 部分没有帮助,因为它“稀释了你的页面排名”。 不确定这有多真实。
You can share cookies between subdomains, provided you set the right parameters in the cookie. By default, they won't be shared, though.
Yes, you can get more simultaneous downloads if you store images in different subdomains. However, the other side of the scale is that the user spends more time resolving DNSs, so it's not practical to have, say, 25 subdomains to get 50 simultaneous downloads.
Another thing that happens with subdomains is that AJAX requests won't work without some effort (you CAN make them work using document.domain tricks, but it's far from straightforward).
Can't help with the SEO part, however, although some people discourage having both yoursite.com and www.yoursite.com working and returning the same content, because it "dilutes your pagerank". Not sure how true that is.
你让很多事情变得复杂了。 收集统计数据、控制蜘蛛、html5 存储、XSS、帧间通信、虚拟主机设置、第三方广告服务、与远程 API(如谷歌地图)交互。
这并不是说这些事情无法解决,只是复杂性的增加增加了更多的工作,并且可能无法提供适当的好处来弥补。
我应该补充一点,我自己曾经在分类网站上走过这条路,添加了 porshe.site.com、ferrari.site.com 等域名,希望提高这些关键字的排名。 最后,我没有看到明显的改进,更糟糕的是,谷歌通过每个子域遍历整个网站,这意味着搜索 ferraris 可能会返回 porsche.site.com/ferraris 而不是 ferrari.site.com/ferraris。 简而言之,谷歌认为每个网站都是重复的,但它仍然在每次访问时抓取每个网站。
同样,解决方法是存在的,但我选择了简单性,我并不后悔。
You complicate quite a few things. Collecting stats, controlling spiders, html5 storage, XSS, inter-frame communication, virtual-host setup, third-party ad serving, interaction with remote APIs like google maps.
That's not to say these things can't be solved, just that the rise in complexity adds more work and may not provide suitable benefits to compensate.
I should add that I went down this path once myself for a classifieds site, adding domains like porshe.site.com, ferrari.site.com hoping to boost rank for those keywords. In the end I did not see noticeable improvement and even worse google was walking the entire site via each subdomain, meaning that a search for ferraris might return porsche.site.com/ferraris instead of ferrari.site.com/ferraris. In short google considered each site to be duplicates but it still crawled each site every time it visited.
Again, workarounds existed but I chose simplicity and I don't regret it.
如果您使用子域来存储网站图像、javascript、样式表等,那么您的页面加载速度可能会更快。 浏览器限制每个域名的同时连接数。 使用的子域越多,可以同时建立的连接就越多,以收集网页内容。
If you use sub domains to store your web sites images, javascript, stylesheets, etc. then your pages may load quicker. Browsers limit the number of simultaneous connections to each domain name. The more sub domains you use, the more connection can be made at the same time to collect the web pages content.
我听到的关于 Google 优化的最后一件事是,域名比子域名更具有页面排名。 我还相信页面排名计算是按页面计算的,而不是按网站计算的(根据算法等)。 尽管唯一能真正告诉你的人是谷歌员工。
您应该能够对所有子域使用 cookie。 www.mysite.com sub1.mysite.com sub2.mysite.com 都可以共享相同的 cookie,但为 mysite.com 指定的 cookie 不能与它们共享。
我不确定你所说的 DL 同时是什么意思。 通常,具有单线程的浏览器一次会下载一张图像,即使是来自不同域的图像。 具有多线程配置的浏览器可以同时从不同域下载多个项目。
The last thing I heard about Google optimization, is that domains count for more pagerank than subdomains. I also believe that page rank calculations are per page, not per site (according to algorithm etc.). Though the only person who can really tell you is a Google employee.
You should be able to use a cookie for all subdomains. www.mysite.com sub1.mysite.com sub2.mysite.com can all share the same cookies, but a cookie specified for mysite.com cannot be shared with them.
I'm not sure what you mean by DL simultaneously. Often times, a browser with a single thread will download images one at a time, even from different domains. Browsers with multiple thread configurations can download multiple items from different domains at the same time.