Hi everyone, this issue only started recently. I upload Weather Display .gif files to my website garfieldweather.com.au. Example summary.gif, trends.gif, signaturebanner.gif and many more. The files are being uploaded to the hosting server OK.
When I view any page I now get the latest cached files. I cannot use the normal refresh browser button any more it just goes back to the cached images. I now need to refresh using CTRL F5 on PC or delete the cache files on my mobile.
The website is used by people in our township to check the weather situation and they are telling me that it has become a pain to use our website.
Iām not sure what has happened but it was working fine in the past. Can someone shed some light on this please and steer me to a solution. I canāt be the only one having this issue, or am I??
Your browser may only be following what your webserver is saying about caching.
The only way to ensure that an image file is not cached by the browser is to add something like <php echo "?t=".time(); ?> to the img src=āsomething.gifā just after the .gif and before the "
This ātricksā the browser into treating it as the dynamic image it is and not caching it.
Many hosters for shared service websites stealthily apply caching instructions to all .jpg,.gif,.png images (and sometimes to .txt files like clientraw*.txt) ā the trick above will usually defeat the caching.
Thanks for your reply ktrue, much appreciated. I am not a programmer and not quite sure how to place the <php echo ā?tā.time(): ?> to the image file - you state just after .gif and before the "
I use a program called website x5 Pro to upload my website and have little control over the html part of it, regarding individual files. I just tell it which file I want to use and it inserts it into the html code. I do have the ability to add some html code to the section.
I also read somewhere else to just place the following into the page header ??
Do you think this might be easier as I do have the ability to add some html code to the section.
Alternative would maybe also contact the hosting people and tell them of the problem. I only recently changed hosting providers and that may be causing the issue to start of with.
Again, anu suggestion would be appreciated especially if you think the system may work.
Those <meta> statements in the <head>...</head> of the page are usually helpful.
However, your website hosting company may be including headers in the response that will override any you specify in the html of the page. Your specs work if the caching headers are not emitted by the webserver.
The only way to tell is to let us know the URL of your weather website, and we can take a look at the returned headers to see if they include caching directories.
If your pages are .html only, then the PHP code I posted wonāt run ⦠the extension on the page has to be .php to run the PHP engine. You can safely rename .html pages to .php pages, even if they have no PHP code on them.
Sorry for not getting back to you sooner. Just heard back from my hosting provider who advised me to place the following code into the .htaccess file - all works a charm now. I have listed the code below in case someone else has the same issue.
Thanks again for your help, I really appreciated it.
.htaccess code as follows
```
# DISABLE CACHING
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
<FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|mp3|mp4|png|pdf|swf|txt)$">
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
<IfModule mod_headers.c>
FileETag None
Header unset ETag
Header unset Pragma
Header unset Cache-Control
Header unset Last-Modified
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
</IfModule>
</FilesMatch>
```
That part, Iād suggest you remove. Having a Last-modified header is quite useful ā it is used by the regional networks to check āfreshnessā of your conditions.
Also the <FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|mp3|mp4|png|pdf|swf|txt)$"> could be better if it was only <FilesMatch "\.(gif|htm|html|png|txt)$">
to better isolate the files that are likely to change frequently and let the other files be cached (and reloaded when Last-modified changes). .jpg files are mostly forecast icons and donāt really change.
WD produces .gif images mostly (unless you selected to use .jpg instead).