且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我必须做些什么才能使通过HTTPS提供的图像等内容在客户端缓存?

更新时间:2022-02-06 21:44:38

如果您通过https提供页面,那么您将需要通过https(来自同一域或其他域,也可以通过https)提供所有包含的静态或动态资源,以避免在浏览器中出现安全警告。

If you are serving a page over https then you'll need to serve all the included static or dynamic resources over https (either from the same domain, or another domain, also over https) to avoid a security warning in the browser.

大多数浏览器默认不会将通过安全通道传送的内容写入磁盘,因此存在于浏览器内存缓存中,这比磁盘缓存小得多。当应用程序退出时,此缓存也会消失。

Content delivered over a secure channel will not be written to disk by default by most browsers and so lives in the browsers memory cache, which is much smaller than the on disk cache. This cache also disappears when the application quits.

尽管如此,您可以采取一些措施来改善单个浏览器设置中SSL资产的可扩展性。对于初学者,请确保所有资产都具有合理的Expires和Cache-Control标头。如果tomcat位于apache后面,那么使用mod_expires添加它们。这将避免浏览器必须检查图像是否在页面之间发生了变化

Having said all of that there are things you can do to improve the cachability for SSL assets inside a single browser setting. For starters, ensure that all you assets have reasonable Expires and Cache-Control headers. If tomcat is sitting behind apache then use mod_expires to add them. This will avoid the browser having to check if the image has changed between pages

<Location /images>
   FileEtag none
   ExpiresActive on
   ExpiresDefault "access plus 1 month"
</Location>

其次,这是MSIE和Apache特有的,大多数apache ssl配置都包含这些行

Secondly, and this is specific to MSIE and Apache, most apache ssl configs include these lines

SetEnvIf User-Agent ".*MSIE.*" \
     nokeepalive ssl-unclean-shutdown \
     downgrade-1.0 force-response-1.0

这会禁用所有MSIE代理的keepalive。恕我直言这太保守了,最后使用SSL的MSIE浏览器是5.x和6.0 SP2的未修补版本,现在两者都非常罕见。以下更宽松,在使用MSIE和SSL时不会禁用Keepalive

Which disables keepalive for ALL MSIE agents. IMHO this is far too conservative, the last MSIE browsers to have issues using SSL were 5.x and unpatched versions of 6.0 pre SP2, both of which are very uncommon now. The following is more lenient and will not disable keepalives when using MSIE and SSL

BrowserMatch "MSIE [1-4]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [5-9]" ssl-unclean-shutdown