简体   繁体   中英

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

I ran my site in 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.

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.

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.

Cache-Control is a HTTP Header that controls caching between the server and client. It is set using the HttpServletResponse like this:

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

Where 60 is the number of seconds to cache for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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