图像分片以及如何避免浏览器缓存中存在多个项目
为了提高页面渲染速度,我正在考虑实现图像分片,该图像分片可提供来自多个子域的图像。如何确保从同一服务器检索到相同的图像?
我想避免像下面这样的情况,即从多个域提供相同的图像: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用内容相对路径的 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.