图像分片以及如何避免浏览器缓存中存在多个项目

发布于 2024-09-01 06:14:43 字数 284 浏览 4 评论 0原文

为了提高页面渲染速度,我正在考虑实现图像分片,该图像分片可提供来自多个子域的图像。如何确保从同一服务器检索到相同的图像?

我想避免像下面这样的情况,即从多个域提供相同的图像: images1.domain.com/image1.gif images2.domain.com/image2.gif images2.domain.com/image3.gif images2.domain.com/image1.gif

我们正在运行 Java - 有没有办法对图像文件名进行校验和/指纹识别,并基于此始终将其分配给同一服务器?

To improve page render speed I am looking at implementing image sharding which serves images from the multiple subdomains. How can I ensure that the same image is retrieved from the same server?

I want to avoid a scenario like the one below where the same image is served from multiple domains:
images1.domain.com/image1.gif
images2.domain.com/image2.gif
images2.domain.com/image3.gif
images2.domain.com/image1.gif

We are running Java - is there any way to checksum/fingerprint the image-filename and based on that always assign it to the same server?

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

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

发布评论

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

评论(1

挽梦忆笙歌 2024-09-08 06:14:43

使用内容相对路径的 MD5 哈希值,然后将其除以您拥有的分片域的数量。这假定 MD5 在输出的最后一位上具有相当均匀的分布(如果您有两个分片)。我在这里的经验是确实如此。这是另一个问题的链接,回答如何生成 MD5 哈希

校验和的模也可能就足够了,并且计算速度更快。

Use an MD5 hash of the relative path to your content, then modulo this by the number of sharding domains you have. This presupposes that MD5 has a fairly even distribution across the final bit of the output (if you have two shards). My experience here was that it did. Here's a link to another question answering how to generate MD5 hash.

A modulo of a checksum might also suffice and be computationally quicker.

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