我在 PageSpeed 中运行我的网站。 它告诉我:
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.
我尝试按照他们在 https://developers.google.com/speed/docs/best-practices/caching 所说的内容来实现它,以及其他一些方式。
但是,到目前为止我还没有成功。也许有人可以帮助我如何做到这一点。
我更喜欢只将图像保留在缓存中。
无论如何,我很想知道如何管理在缓存中保存和不保存文件
我的网站是使用 Google 应用程序引擎和 Java 服务器页面开发的。
最佳答案
Cache-Control
是 HTTP Header控制服务器和客户端之间的缓存。它是使用 HttpServletResponse
设置的,如下所示:
httpResponse.addHeader("Cache-Control", "max-age=60");
其中 60
是缓存的秒数。
关于java - 如何在 Java 服务器页面中使用 Cache-Control 和 Expires header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18121622/