I see a lot of answers about forcing cache reload recommending a solution that incorporates the HTML page itself.
But when you have a situation where your old website was written as an index.html
homepage, and now you swap that with something new, how do you make sure that a returning visitor sees the new content?
The old website used to have index.html
as the index page (in nginx
's configuration), which i have now changed to index.php
. But whenever i visit it from a browser that has visited it previously, it still opens the cached old index.html
page. A new browser will load index.php
correctly.
One of seemingly correct answers i found, was to tell nginx
to set expires -1;
for the server {}
section, which would force the cache to invalidate; but for some reason that didn't work.
What needs to happen, of course, is that the visitors will always get the new page, without explicitly issuing a refresh themselves.
Presumably the solution should be to invalidate the cache through headers. But how?
Edits to address all the suggested comments and answers
- Like i said in the first paragraph of my answer, this issue is not solved by editing the index file (like adding parameters for "cache busting"), because the index file itself has been cached, that is the problem.
- I have nowhere in my question mentioned javascript or CSS files. Again, it's the
index.html
file that has been cached. - The existence of
index.html
andindex.php
does not create conflicts. The entire system is working correctly, it's only the old visitors who have previously visited the page back whenindex.html
was set as the index page in the server configuration, that still get the cachedindex.html
as the homepage even after the index has been changed toindex.php
. This is also very easily provable by the fact that this problem still happens even after theindex.html
file is completely deleted. Because once the browser caches an HTML file, it no longer asks the server for what the index file is, it just shows what it has cached.
So the complete scenario is this:
- The website has
index.html
set as the index page in the server configuration - Browser visits the website
- Browser caches the homepage
- The index page in the server configuration gets changed to
index.php
- Same browser visits the website
- Browser shows cached
index.html
from before
In number 5., if i were to visit the website with a new browser, it will show the contents of the new homepage that is in index.php
. So the question is, how do i get the old browser to forget what it has cached, and load the new homepage?