2

Recently I tried to make sure that some of the images on my website are not cached by the browser.

I came across several questions like
Preventing Images being cached in the browser
How to prevent browser image caching?
How to prevent browsers from caching an image?

But since a short time the solution that they provided stoped working for me.
I have serveral images on my website but there is only one that I do not want to cache.

I used <img src="/img/img.jpg?1275332" />
Where the number was the current time stamp.

Is there any other way to prevent the browser from caching?
And does any one has an idea why this isn't working (anymore)?

Edit:
The image that I do not want to cache is not a static image.
When a user changes one of his images, only the changed image need to be updated. Thats why I tried to add a timestamp after the changed image.

The application is also a SPA so there wont be any page refresh.

Community
  • 1
  • 1
Szenis
  • 4,020
  • 2
  • 21
  • 34

1 Answers1

1

You can use a application-cache manifest file. For that you need to add it to your html page in following manner :

<!doctype html>
<html manifest="myapp.appcache">
<head>...</head>
<body>...</body>

In your application-cache manifest specify the image in the NETWORK section. The NETWORK section is used to specify urls that must never be cached and should always be retrieved from the network.

CACHE MANIFEST

CACHE:
#html page, scripts etc you want to cache

FALLBACK:
#fallback resource if cached version is not available.

NETWORK:
#image path you don't want to cache

More control of this whole process can be achieved by attaching event handlers to window.applicationCache events like onupdate, oncached, ondownloading, onprogress, onobsolete

I hope this would solve your issue.

Akshay Soam
  • 1,580
  • 3
  • 21
  • 39
  • It looks like a good solution but there is one problem, all the images in the list come from **/img/thumb/**. so if I use ````NETWORK: apirul/img/thumb/```` then none of the images will be cached. But +1 for .appcache cause I think it can help other people. – Szenis Aug 13 '15 at 11:24
  • I understand that I can use the file name. Wait I will expand my question to explain the exact scenario. – Szenis Aug 13 '15 at 11:35