0

I want to make the js and css files which are modified are to be downloaded at the client end when a page is accessed. I have these approaches

  1. Manually add the modified timestamp the URL in each page.
  2. I was thinking of writing a scriptlet code in all the jsp pages which will read all the js and css files modified timestamp and append it to the url in the page.
  3. Add the modified timestamp while building the war file using ANT.

I have following questions.

  1. Can any one let me know which would be a better solution of the above approaches? I am open to any other solutions also.
  2. I went through this answer on SO and using it I can get the modified date but how to change the jsp file?
  3. Is there anything similar to this in java?
Community
  • 1
  • 1
Natraj
  • 397
  • 4
  • 9
  • 35

1 Answers1

0

In this situation better or best solution is took shape according to your exact requirements. I might derive simple questions like; Will your static resources in same server or included in your app in same server etc.. May be some other better ways..

I don't have ant experience so I can't talk about it now , but you can go with java way already.I want to share just idea/s. A filter(looks the .css or .js requests , gets resources and look resource lastmodified date or checksum return as version on response) or custom jsp tag will provide your requirements. Write a custom jsp tag <resource:static path="app.js"/> like that example. So it may look specific file's last modified date, assumed under the same document root, and it can produce <script type="text/javascript" src="app.js?version=8637"> like this result, so this result will bust the cache.

İlker Korkut
  • 3,129
  • 3
  • 30
  • 51