Cache control

Cache control is a set of HTTP headers sent by the server to control how the user's browser is allowed to cache resources.

In the previous chapter, we have seen that Spring Security automatically disables caching for secured resources.

If we want to benefit from cache control, we must first disable that feature:

security.headers.cache=false

# Cache resources for 3 days
spring.resources.cache-period=259200

Now, launch the application, go to the main page, and check the Chrome developer console. You will see that our JavaScript files are Gzipped and cached, as marked in the following screenshot:

Cache control

If you want more control over your cache, you ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.