0

There are some images present on my web page which we do update from back end. But those images not getting reflect directly means user need to do ctr+F5. It means client's browser cached that images. Is there any way to reload updated images, JS, CSS once thay got updated?

What I have try from my side.

ETag

Which didn't work for me.

Added following tags in my page header

<meta http-equiv="Expires" CONTENT="-1" ></meta>

<meta http-equiv="cache-control" content="no-cache"></meta>

<meta http-equiv="Pragma" CONTENT="no-cache"></meta>

But same result.

Added following configurations in Apache

ExpiresActive on
ExpiresByType application/javascript "access plus 0 seconds"
ExpiresByType image/jpg "access plus 0 seconds"
ExpiresByType image/jpeg "access plus 0 seconds"
ExpiresByType image/gif "access plus 0 seconds"
ExpiresByType image/png "access plus 0 seconds"
ExpiresByType text/css "access plus 0 seconds"

Above configurations works for JS. But facing problem with images. I can't add any token number or version number at the end of url/image name which required too much code change and testing too. Please guide me is there any other centralized way to restrict images,css from caching

Thanks in Advance.

1 Answer 1

1

You can use javascript to change the src of any image, this will cause the name to change and force the browser to reload.

Example:

document.getElementById('myimg').src = document.getElementById('myimg').src + '?r=' + Math.random();

Not the cleanest solution but it seems your options are limited.

To reload the entire pages images with jQuery you could try:

$('img').each(function() {
    $(this).attr('src', $(this).attr('src') + '?r=' + Math.random())
});

By modifying the initial selector you can limit it to an area so you don't end up reloading everything. This will not effect images specified by css styling.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your replay, But as I mention I am not able to do code change. Want some centralize solution so that just change on one place and reflect it in application.
Have you checked apache settings? Apache Help
Yes. it's same which I have given above. Above configurations I got from Same link which you pass in above comment.
If you can modify the page headers why can't you add a javascript file tag?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.