-1

I have a webapplication based on Html/css - JavaScript (Frontend) and Java (Backend). Now I got the problem that the browsers do cache my webpages. I read all about the ways to not cache but I can't find out how I can implement this.

What is the best way and where (html / javascript or java) can I disable the cache. And how can I disable this?

Tunaki
  • 116,530
  • 39
  • 281
  • 370

3 Answers3

2

The best way is with .htaccess

Something like:

<FilesMatch "\.(html|htm|js|css|php)>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</FilesMatch>

will disable cache for html, htm. js, css, php files.

More on .htaccess: https://httpd.apache.org/docs/current/howto/htaccess.html

Marin Nedea
  • 376
  • 2
  • 12
0

Add this meta tags to your Html headers which ensures your page on disabling the cache mechanism with any browser

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
san544
  • 52
  • 9
0

Firstly please consider using a very long cache instead, and simply change the name of each resource by adding a version number to that file name. You can have your landing URL be a briefly cached redirect to the latest version.

We need to find out what web server you are using. IIS, Apache, or Nginx are the most common, you can configure how each file type is cached in their respective configuration files. What you are needing to change are HTTP response headers.

James Wakefield
  • 528
  • 3
  • 10