为多个网站提供来自一个域的图像
我们公司内有近 13 个域,我们希望从一个应用程序提供图像以利用缓存。
例如,我们将有 c1.example.com,我们将把所有产品图像放在该应用程序下。但在这里我有一些疑问;
1-如何强制客户端浏览器缓存图像并且不再请求它?
2-当我在我的应用程序中引用这些图像时,我将使用以下 html 标记;
<img scr="http://c1.example.com/core/img1.png" />
但是当我在 https 下运行网站时,这会导致问题。它给出有关该页面的警告。当我在 https 下运行我的应用程序时,应该使用 https://c1.example.com/core/img1.png 。我应该在这里做什么?我应该始终使用 https 吗?或者有没有办法在自动之间切换?
我将在 IIS 7 下运行我的应用程序。
we have nearly 13 domains within our company and we would like to serve images from one application in order to leverage caching.
for example, we will have c1.example.com and we will put all of our product images under this application. but here I have some doubts;
1- how can I force client browser's to cache the image and do not request it again?
2- when I reference those images on my application, I will use following html markup;
<img scr="http://c1.example.com/core/img1.png" />
but this causes a problem when I run the website under https. It gives warning about the page. It should have been used https//c1.example.com/core/img1.png when I run my apps under https. what should I do here? should I always use https? or is there a way to switch between auto?
I will run my apps under IIS 7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,当 html 页面通过 https 提供服务时,您需要通过 https 提供所有资源。这就是使用 https 的全部意义。
如果 href 被硬编码在 html 中,一种解决方案可能是使用响应过滤器来解析发送到客户端的所有内容,并在必要时用 https 替换 http。一个简单的正则表达式就可以解决问题。有 大量文章 那里有关于这些过滤器如何工作的信息。
关于缓存,您需要发送正确的缓存标头和 etag。有几个关于此的问题和答案,例如 IIS7 Cache-Control
Yes you need to serve all resources over https when the html-page is served over https. Thats the whole point of using https.
If the hrefs are hardcoded in the html one solution could be to use a Response Filter that will parse all content sent to the client and replace http with https when necessary. A simple Regular Expression should do the trick. There are plenty of articles out there about how these filters are working.
About caching you need to send the correct cache-headers and etag. There are several of questions and answers on this on SO like this one IIS7 Cache-Control
您需要使用 HTTP 标头来告诉浏览器如何缓存。默认情况下它应该可以工作(假设您的 URL 中没有查询字符串),但如果没有,这里有一篇关于缓存控制标头的知识库文章:
http://support.microsoft.com/kb/247404
我真的不太了解 IIS,所以我不确定是否还有其他潜在的陷阱。请注意,浏览器有时仍可能发送 HEAD 请求。
我建议您设置图像服务器,以便 HTTP/S 可以互换,然后只需从 HTTPS 请求提供 HTTPS 网址。
You need to use HTTP headers to tell the browser how to cache. It should work by default (assuming you have no query string in your URLs) but if not, here's a knowledge base article about the cache-control header:
http://support.microsoft.com/kb/247404
I really don't know much about IIS, so I'm not sure if there are any other potential pitfalls. Note that browsers may still send HEAD requests sometimes.
I'd recommend you setup the image server so that HTTP/S is interchangeable, then just serve HTTPS Urls from HTTPS requests.