3

This is similar to the discussion in the following link.

I want to enable browser caching by setting an expiry date or a maximum age in the HTTP headers for the static resources. The application which I'm trying to make this change is a complete JavaScript project, which runs on Tomcat.

Is there any server configuration to add headers for static resources?

Community
  • 1
  • 1
Edi
  • 327
  • 4
  • 16

2 Answers2

2

You can: click here

But tomcat is a java servlet container, why you use it to serve static resources? You should use nginx for static sources.

笑笑十年
  • 101
  • 5
  • The company which I'm working for wants it to run on Tomcat for now since they are already familiar with that. Also the link which you have provided does not contain attributes related to caching? – Edi Dec 22 '14 at 08:33
  • 1
    I'm sorry to paste the wrong link, I have update the link, you may be should add a filter to add http headers. – 笑笑十年 Dec 25 '14 at 04:04
0

You can't do this from JavaScript, this is the job for your web server, in this case Tomcat. This question is about what you want to achieve. Make a servlet for your static content, and set the headers there.

Or as mentioned in the other answer, the more complex (but more performant) solution would be setting up another server like Apache2 or nginx for the static resources, and set it up as a reverse proxy for your servlets. However I would not recommend this for simple projects, it is a fair amount of work.

This question also worth a look: Tomcat Cache Control

Community
  • 1
  • 1
meskobalazs
  • 15,741
  • 2
  • 40
  • 63