Reputation: 36081
Is there a way that I can force a page to reload, but only if it has been updated recently? I am working on a photography website so there are a lot of images, therefore it is best if it is cached.
However, if the content has been updated (e.g. more photographs added) then I want the browser to load a fresh copy, if not then use the version in the cache?
I was hoping that there was a meta tag that would take care of it. I've read about the expires tag but that wouldn't help as the page isn't updated regularly.
I'm only using CSS, HTML and Javascript, nothing server side. Any suggestions welcome.
Upvotes: 1
Views: 2243
Reputation: 655269
I think the best would be to use HTTP caching mechanisms. If you can’t use server side languages to send appropriate HTTP headers, try a built in solution like Apache’s mod_expire module. With that you can set a maximum age based on the request time:
ExpiresByType text/html "access plus 1 week"
Upvotes: 3
Reputation: 44752
You can use an ETag
.
HTTP 1.1 introduced a new kind of validator called the ETag. ETags are unique identifiers that are generated by the server and changed every time the representation does. Because the server controls how the ETag is generated, caches can be surer that if the ETag matches when they make a If-None-Match request, the representation really is the same.
Excellent information about caching can be found here.
Upvotes: 3