简体   繁体   English

如何在Java Server Pages中使用Cache-Control和Expires标头

[英]How to use Cache-Control and Expires headers in Java Server Pages

I ran my site in PageSpeed. 我在PageSpeed中运行了我的网站。 It tells me: 它告诉我:

Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network. 在HTTP标头中为静态资源设置有效期限或最长期限,将指示浏览器从本地磁盘而不是通过网络加载以前下载的资源。

I tried to implement it according to what they say at https://developers.google.com/speed/docs/best-practices/caching , and in some other ways. 我尝试根据他们在https://developers.google.com/speed/docs/best-practices/caching上所说的以及其他一些方式来实现它。

But, so far I didn't succeed. 但是,到目前为止,我没有成功。 Maybe someone can help me how to do it. 也许有人可以帮我怎么做。

I prefer to keep only the images in the cache. 我更喜欢只将图像保留在缓存中。

Anyway I would love to know how I can manage saving and not saving files in the cache 无论如何,我很想知道如何管理和不保存文件到缓存中

My site is being developed with the Google Application Engine and Java Server Pages. 我的网站正在使用Google Application Engine和Java Server Pages开发。

Cache-Control is a HTTP Header that controls caching between the server and client. Cache-Control是一个HTTP标头 ,用于控制服务器和客户端之间的缓存。 It is set using the HttpServletResponse like this: 使用HttpServletResponse设置,如下所示:

httpResponse.addHeader("Cache-Control", "max-age=60");

Where 60 is the number of seconds to cache for. 其中60是要缓存的秒数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM