平衡浏览器的图像缓存和链接的过期时间,以避免带宽被盗

发布于 2024-09-10 09:54:00 字数 406 浏览 1 评论 0原文

我们在 Amazon S3 上托管图像,并通过 Amazon Cloudfront 提供服务。我们希望减少带宽费用。我们认为存在相当多的带宽盗窃行为,并希望开始使用签名 URL 来防止这种情况发生。然而,我们必须平衡这一点,因为每次我们发送新的签名 URL 时,都会使浏览器的图像缓存失效。

我们当前的计划是生成一个有效期为两个月的签名 URL,然后将其缓存在本地并提供一个月,然后再生成新的签名 URL。这将使浏览器可以更长时间地缓存图像。然而,这也意味着任何人都可以在长达两个月的时间内窃取图像的带宽。

有没有办法让链接早点过期,但让浏览器继续缓存该图像?我知道当 url 为新的时间戳而辞职时,图像的 etag 和 If-Modified-Since 不会改变,但浏览器不再知道在标头中发送这些值,因为就其而言,这是一个新的网址。有什么办法可以解决这个问题吗?

We host our images on Amazon S3, and serve them through Amazon Cloudfront. We'd like to reduce our bandwidth expenses. We believe that we have quite a bit of bandwidth theft, and want to start using signed URLs to prevent this. However, we have to balance this against the fact that each time we send out a new signed url, it invalidates the browser caches for the image.

Our current plan is to generate a signed url that is valid for two months, then cache it locally and serve it for a month, before generating a new signed URL. This will allow the browser to cache the images for longer. However, this also means that anyone can then leech bandwidth for an image for up to two months.

Is there any way to have the link expire sooner, but have the browser continue to cache that image? I know that the etag and If-Modified-Since for the image do not change when the url is resigned for a new timestamp, but the the browser no longer knows to send those values in the header, because as far as it is concerned, this is a new URL. Is there any way around this problem?

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

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

发布评论

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

评论(2

独留℉清风醉 2024-09-17 09:54:00

您是否测量过有多少带宽被盗?即,检查您收到的图像请求数量,这些请求没有将引用字段设置为您自己的网站。

为了获得最佳缓存,我们建议缓存 10 年,所以 2 个月听起来有点短。

Have you measured how much of your bandwidth is being stolen? ie, check how many requests you get for your images that don't have a referrer field set to your own site.

For optimum caching, we recommend caching for 10 years, so 2 months sounds like a little short.

回首观望 2024-09-17 09:54:00

需要多少缓存很大程度上取决于网站访问者的访问模式。对于大多数网站,我认为提供一个月的缓存应该足以获得有效的缓存。

在投入大量精力之前,您应该对水蛭的实际成本进行具体评估,并将其与解决问题的所有成本进行比较。

顺便说一句:在某些情况下为图像添加水印也非常有效。

How much caching is needed depends very much on the access pattern of the visitors on your website. For most sites I would say giving one month of caching should be more then enough to get effective caching.

Before putting a lot of effort into this you should put a concrete value to the actual cost of the leeching and put that against all the costs of solving the problem.

BTW: watermarking your images is in certain cases also very effective.

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