Saturday, 17 August 2013

Is it possible to disable browser caching with code?

Is it possible to disable browser caching with code?

I know that there are other posts about disabling caching. I've read all
of them that I can find and am still having a problem, so please be kind
and don't kick me for starting a new thread.
Here's the deal, I am working on a site that a landlord can use to list
all of their properties. It's sort of like an MLS based site that a
realtor would use.
The problem that I'm having wouldn't be a problem for me, but it will be
for my client who isn't very bright (I can say that, she's a family
member). Once a property is set up and all of the various pictures are
uploaded there is an option to edit any of that data as well as delete any
of the existing pictures. If you delete a picture, all works well but the
browser caching makes it appear as if nothing happened. Hit F5 (in
Firefox) to refresh the page and everything looks like it should.
The problem has to do with how I chose to name the photos that are
uploaded. The photos are renamed using the property address info with the
number of the picture appended. For example: 3505Cardinalpic1.jpg,
3505Cardinalpic2.jpg, 3505Cardinalpic3.jpg, etc. If I were to delete the
first one, for example, the following pictures are renamed to keep the
naming order intact. They would be come 3505Cardinalpic1.jpg, and
3505Cardinalpic2.jpg, for example. Both surviving pictures are the 2nd and
3rd pictures from the pre-existing sequence of 3.
When the page reloads after one picture is deleted, it loads the pictures
from cache because the filename didn't change, only the source file
itself.
I figure that I could fix this by rewriting my php that handles the
pictures so that the file name is appended with a timestamp or something
that would make each name still recognizable but unique but I want to make
sure there is no easier way to do that before I go in there and futz with
something that's working.
I'm intentionally not posting code because I don't think it's a code issue
and the problem description is already long enough. If you'd like to see a
section of my code, just ask.
I've tried this with no luck:
test php disabled caching
I've tried appending my url with a timestamp to make it unique and that
didn't help either.
Thanks in advance for any advice.

No comments:

Post a Comment