通过 CloudFront 加载 CSS 图像精灵比本地加载慢

发布于 2024-09-26 18:28:18 字数 84 浏览 6 评论 0原文

我刚刚将 CSS 图像精灵更改为从本地运行到 CloudFront,现在即使跨页面和页面重新加载也会出现明显的延迟。关于为什么会发生这种情况有什么想法吗?

I just changed my CSS image sprites to run from local to CloudFront and there's now a noticeable lag, even across pages and page reloads. Any ideas as to why this might be happening?

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

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

发布评论

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

评论(1

伴我老 2024-10-03 18:28:18

将图像从 localhost 移动到服务器(在本例中为 CloudFront)将始终会产生速度损失(当然是相对于localhost)。这是因为,即使使用出色的托管服务,浏览器也必须通过互联网该服务器发送http请求,以查明文档自上次修改以来是否被修改过缓存或未缓存(未修改:HTTP 响应 304)。

假设文档不需要再次下载/重新缓存,这应该是 CSS 图像请求的结束(特别是如果您使用 css-sprites)。

如果由于缓存已过期或文档已更改而必须重新下载图像精灵,那么显然浏览器必须通过互联网和网络再次下载文件。由于您自己的网络/内联网、您的房子和邻居之间、家庭和机柜之间的争用以及您的 ISP 为您提供的任何速度,这都会产生费用。

localhost 是同一台机器,并且(可能)具有以毫秒为单位的响应。相比之下,访问 Amazon 的 CloudFront 可能只需要一两秒,但这仍然要大一个数量级(或更多)。

Moving images from localhost to a server (in this case CloudFront) will always incur a speed penalty (relative to localhost, certainly). This is because even with a great hosting service the browser has to send an http request via the internet to that server, to find out whether the document's been modified since it was previously cached, or not (not modified: HTTP response 304).

Assuming that the document doesn't need to be downloaded again/re-cached that should be the end of the image-requests for the CSS (particularly if you're using css-sprites).

If the image-sprites have to be re-downloaded because the cache has expired, or the document's changed, then obviously the browser has to download the file again, via the internet and network. And this incurs a cost due to contention on your own network/intranet, between your house and your neighbours between home and cabinet and then whatever speed your ISP provides to you.

Whereas localhost is the same machine, and (likely) has a response measured in the milliseconds. In contrast, accessing Amazon's CloudFront might only take a second or two, but that's still an order of magnitude (or more) greater.

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