浏览器是否缓存动态图像?

发布于 2024-11-25 04:41:09 字数 261 浏览 0 评论 0 原文

我目前正在开发一个将由多个客户使用的网络应用程序,我希望在每个页面上显示客户的徽标。该应用程序是使用 ASP.NET MVC3 和 C# 开发的。

正常惯例建议将图像存储在数据库中,但考虑到该图像将显示在每个页面上,我担心这样做会对性能造成影响。如果我将图像存储在文件系统上,浏览器将缓存该图像并且不会每次都请求它。

如果我将图像存储在数据库中,浏览器是否也会缓存该图像,或者每次都会调用函数来请求图像?

在这种情况下,我是否将图像存储在服务器的硬盘上会更好?

I am currently developing a web application which will be used by multiple clients, and I wish to display the clients logo on each page. The application is being developed using ASP.NET MVC3 and C#.

Normal convention suggests storing images in a database, but given that this image will be displayed on every page, I am concerned about the performance hit of doing this. If I store the image on the file system, the browser will cache the image and wont request it each time.

If I store the image in the database, will the browser also cache this, or will it call the function to request the image each time?

In such a case would I be better off storing the images on the hard disk of the server?

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

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

发布评论

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

评论(3

格子衫的從容 2024-12-02 04:41:09

(现代)浏览器不知道服务器如何存储图像。如果 URL 相同,浏览器将只提取缓存的版本,除非明确告知不要这样做。

在某些情况下,您可能需要禁用缓存:http://www.example.com/random-image 可能会在每次访问时提供不同的图像,并且浏览器将缓存第一个图像图像已送达。

The (modern) browser doesn't know what the server did to store the image. If the URL is the same, the browser will just pull up the cached version unless it was explicitly told not to.

In some circumstances you may need to disable caching: http://www.example.com/random-image would probably serve up a different image each time it was accessed, and the browser would cache the first image served up.

扎心 2024-12-02 04:41:09

在动态图像控制器中适当设置 Response.Cache 标头,它来自动态源并不重要。

查看这篇文章,了解使用 MVC ActionFilter 设置缓存的想法: http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx。它还说明了您需要调整的标题。

Set the Response.Cache headers appropriately in your dynamic image controller, and it won't matter that it comes from a dynamic source.

Check this post for an idea for setting caching using an MVC ActionFilter: http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx. It also illustrates the headers you'll need to tweak.

兔姬 2024-12-02 04:41:09

图像通过其 URL 进行缓存。如果自上次加载页面后 URL 未发生更改,则将从缓存中获取图像。

Images are cached by their URLs. If URL has not changed since last load of the page, the image will be taken from cache.

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