了解如何提供和缓存图像
所以我想知道浏览器如何处理图像请求。我希望使用 CDN 在我的网站上提供产品图像。我还想使用 cdn 来提供按钮图像和 css 中使用的图像。
问题是我无法控制过期标头(我正在研究 Rackspace 文件)。
假设我的主页上有一个大图像文件作为背景。因此该页面经常被访问,但图像保持不变。浏览器每次都会请求这张图片吗?
或者我应该只使用 CDN 来存储我的产品图片?
So I'm wondering how browsers treat requests for images. I'm hoping to use a cdn for serving product images on my website. I'd also like to use the cdn for serving button images and images used in my css.
The problem with this is that I don't have control over the expires headers (Rackspace files is what I'm looking into).
See, say I have a large image file as a background on my home page. So the page is accessed often, but the image stays the same. Is the browser going to request this image every time?
Or should I just use a cdn for my product images?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
缓存是一个相当广泛的主题。我建议您首先阅读这里的不同类型的缓存 http://www.mnot.net/ cache_docs/#BROWSER 以及缓存的工作原理 http://www.web -caching.com/mnot_tutorial/how.html
现在,回答您的问题:假设用户启用了缓存并且正确配置了 cdn 响应标头,则多次访问您页面的用户只会请求该背景图像一次,直到缓存过期或这些文件已被清除。
caching is quite a broad subject. I suggest you start by reading about the different kinds of caching here http://www.mnot.net/cache_docs/#BROWSER and how caching works here http://www.web-caching.com/mnot_tutorial/how.html
Now, to answer your question: assuming the user has caching enabled and the cdn response headers are properly configured a user visiting your page multiple times will only request that background image once until the cache expires or those files are cleaned.
不,据我所知,您必须将“缓存”标头添加到图像中才能启用浏览器缓存。 这是一个很棒的教程。
此外,您还可以阅读 Yahoo 的这篇文章,以简要了解这些主题。
特别回顾本文的以下主题:
希望它对您有帮助
No, AFAIK you need necessarily to add the 'cache' header to your images to enable browser caching. This is a great tutorial about it.
Additionally you can read this article from Yahoo to get a very brief view of the topics.
Review specially these topics of the article:
Hope it helps you