通过 IP 地址而不是域来调用图像是个好主意吗?

发布于 2024-08-03 12:28:07 字数 369 浏览 2 评论 0原文

假设有一个页面,其中显示了 100 张不同的用户照片,
那里至少有 100 个 DNS 查找,如果我使用 IP 而不是域 URL 进行链接,这会减少吗?

http://217.345.33.444/images/photo.jpg而不是 http://domain.com/images/photo.jpg

Let's say there is a page with 100 different user photo's shown on the page,
that is at least 100 DNS lookups right there, would this be reduced if I were to link using the an IP instead of a domain url?

http://217.345.33.444/images/photo.jpg instead of http://domain.com/images/photo.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

嗼ふ静 2024-08-10 12:28:07

它降低了 DNS 查找开销,但如果该 IP 将来发生变化,则会强制进行痛苦、单调且容易出错的更改。

此外,一旦解析了单个名称,就不应该再次查找它......

It lowers DNS lookup overhead but will force painful, monotonous, error-prone changes if that IP ever changes down the road.

Also, once a single name is resolved, it shouldn't be looked-up again ...

夏花。依旧 2024-08-10 12:28:07

对于我所在的时区来说,已经是深夜了,但我认为 DNS 查找缓存在各个位置(甚至在本地计算机上??),所以它并不像您想象的那么糟糕。

因此,第一次调用查找域将会以公平的方式进行,但结果应该缓存在中间的机器上,以便以后的调用对性能的影响较小。

我确信 DNS 协议的设计者对这类事情进行了长期而认真的思考。

编辑笔记

我花了 3 次编辑才把拼写和语法搞清楚 - 这对我来说绝对是太晚了

Its a bit late at night for my timezone, but I thought that DNS lookups are cached in various spots, (even on the local machine??) so it is not as bad as you think.

Thus the first call to lookup the domain will travel a fair way, but the results should be cached on in-between machines so that there is less performance hits with the later calls.

I am sure that this sort of thing was thought long and hard about by the designers of the DNS protocols.

Edit notes

Its taken me 3 edits just to get my spelling and grammar straight - it is definitely too late at night for me

绅士风度i 2024-08-10 12:28:07

DNS 查找由您的计算机缓存,因此每个唯一域只会进行一次查找。

此外,大多数人使用互联网提供商的 DNS 服务器,它通常也会缓存 DNS 查找,因此很多时候,DNS 查找只需一个网络跃点即可。

您无法知道域的 IP 地址何时会发生变化,因此我不推荐这种方法。

您不将图像存储在您自己的域中是否有原因?如果您这样做:

  • DNS 问题就会消失。
  • 许多网络服务器不允许图像热链接,因此这个问题也将得到解决。
  • 如果一起显示的图像集不经常变化,这也将创造将图像分割在一起的可能性。

DNS lookups are cached by your computer, so there will only be a single lookup per unique domain.

Additionally, most people use their internet provider's DNS server, and it will typically cache DNS lookups as well, so a lot of the time, the DNS lookup will just be a single network hop away.

You have no way of knowing when the IP address of a domain will change, so I do not recommend this approach.

Is there a reason you don't store the images on your own domain? If you did that:

  • the DNS issue would go away.
  • A lot of web servers don't allow hot linking of images, so this problem would be solved as well.
  • that would also create the possibility of spriting images together, if the set of images shown together doesn't change often.
小猫一只 2024-08-10 12:28:07

为什么是 100 次 DNS 查找?所有图像都在不同的域中吗?您通常应该只对每个唯一域进行一次查找(假设该域以前从未被解析过)。

Why is that 100 DNS lookups? Are all the images on different domains? You should only typically incur one lookup per unique domain (and that's assuming that domain has never been resolved before).

娇纵 2024-08-10 12:28:07

您对自己的 IP 地址永远不会改变有多大信心?此外,如果您在 4 个不同的域上拥有这 100 个图像,性能也会提高。

How confident are you that your IP address will never change? Also if you had those 100 images on 4 different domains performance would increase.

素年丶 2024-08-10 12:28:07

我所知道的每个浏览器都只查找 DNS 一次,然后将其缓存。即使没有,系统也会这样做。没有像您怀疑的那样进行 100 次查找。

您可以使用任何简单的流量嗅探器来证明这一点,就像我所做的那样。

Every browser I know looks up for the DNS only once and than cache it. Even if it doesn't, the system does. There's no 100 lookups as you suspected.

You can take a proof of that with any simple traffic sniffer, as I did.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文