Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing refresh of a background image

Tags:

Is there a way to make sure that a certain background image recently updated does appear in its last version on everybody's browser (rather than the old version stored in cache)?

It has to be a solution not involving touching the line of code calling the CSS (I could put a question mark and a version number after the css file name, like : <link href="styles.css?v=2" rel="stylesheet" type="text/css"/>, but in this case I don't have access to this part of the code)

like image 497
drake035 Avatar asked Sep 28 '12 11:09

drake035


2 Answers

You can use the following approach:

.button {
    background: url(../Images/button.png?v=1234);
}
like image 188
Anshu Avatar answered Sep 21 '22 03:09

Anshu


You can add another CSS rule after the other CSS, that overrides the rules that loads the image and uses an image with an added version number.

CSS rules loaded later have higher priority, so you can use the same selector as in the main CSS, and it will override it.

If you can't do that, then you are screwed. You have to change the URL of the image that is loaded to surely get the new image.

like image 36
Guffa Avatar answered Sep 23 '22 03:09

Guffa