I changed the .htaccess file to cache everything for a year.
After a while, I noticed that I don't see the updates I make to the website.
I figured out, that because I changed the default cache to a year, somehow the html file got cached for 1 year, and even though I've changed it back, still doesn't work.
The only way I could make it update is to use different links (like www.domain.com/newlink insead of www.domain.com/oldlink), but that doesn't repair my frontpage, as it is www.domain.com, and I can't change that.
Do you have any solution for my problem?
P.S. It isn't my browsers cache, as I have cleared it's cache, I even reinstalled it, and if that's not enough, I can't see the updated version on my phone.
P.P.S. I can see that the http request doesn't even reach the server for the www.domain.com link.
P.P.P.S. I tried using a proxy, and the page worked as it should, so I think it's only cached at my ISP.
Can you try to explicit say not to cache to apache in the htaccess. Also restarting your apache server might work.
<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
Related
I have a Wordpress site running a plugin called OpenHours. Basically, we program in our operating hours to the backend of the site and then have a page /hours/ which shows them. I have disabled every possible Caching feature in Wordpress and tried editing the .htaccess file with the below:
# 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>
We have a mobile app that basically links users to the webpage through their phone's browser, but anytime the link is clicked the page doesn't update (The plugin is configured to show "Currently Open" or "Currently Closed" based on time of day). Is there a way to force the page to update and not cache whenever it is visited?
I tried a query string but unfortunately the spot we insert the link in the app does not support any type of coding, just a straight link, so /hours/?rnd="+Math.random() and /hours/?rnd="+new Date().getTime() haven't worked.
You can set new headers for a specific page using the default PHP header function.
add_action("init", function() {
// TODO: Replace with the actual page ID or title
if(!is_page("page-without-cache")) return;
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
}, 10);
We used the init function to make sure that the header is sent before rendering the page.
And if you are using any cache plugin, you should be able to create a list of URLs or directories that you do not want to include or that you do not want to be cached. For example, in the WP Super Cache plugin, the option is located in the Advanced tab > Accepted Filenames & Rejected URIs section. By default, these paths are excluded from cache.
wp-.*\.php
index\.php
And in addition, WP have dedicated functions called nocache_headers or wp_nocache_headers, which you can also use to prevent caching. The functions are also using the default PHP header function.
Now this bug has lasted long enought. I have tried everything to stop the caching. Everything on the following stackoverflow links:
Chrome - Disable cache for localhost only?
Disabling Chrome cache for website development
Using <meta> tags to turn off caching in all browsers?
How to prevent Browser cache for php site
How to control web page caching, across all browsers?
How to prevent http file caching in Apache httpd (MAMP)
And also i tried to rightclick on the reload button on chrome and choose reload page complete and empty cache and reload page completely. I use PHPStorm as IDE but i also tried switching to notepad++ in case PHPStorm wasn't saving the file properly. Tried setting timestamps in the header so my requests to the page isn't identical. I am running on localhost XAMPP. Any solutions/ideas/guesses are more than welcome.
Note
Restarting XAMPP actually clears the cache (or at least forces the browser to reload the content). I have no idea why. Thanks in advance
Note
My PHP codes are being cached as well. When i edit my PHP codes and i refresh the page, it runs the old codes again. It's probably because the browser still shows the cached version of the page but thought it was worth mentioning.
There isn't much info here; but you might want to have a look at your php.ini and especially your revalidate_freq. It should preferably be 0 for development; but definitely not bigger than then default of 2 seconds.
Create a .htaccess file under root directory and put the below code inside .htaccess file.
check if you have mod_rewrite enable in the server (optional).
Add it stops caching the pages
#Initialize mod_rewrite
RewriteEngine On
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>
Please check below mentioned solution, It will help you.
Step 1:
In HTML head tag you should add below mentioned lines.
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
So with this when user visits your page, every time new content will fetch from server.
Step 2:
By using .htaccess you can prevent page 100% being cached by browser.
<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
Step 3:
If your page is in PHP than add this line on the top of the page.
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: 0");
Let me know if it not works.
i install a chrome Extension that clear cache. i config it to clear cache with CTAL+Q - so insead of refresh page with F5 or CTRL+R i use this Extension - it solve my developin cache problems ( i use polymer framework - and i have same problems as you )
i use this extension
I HAve a Website http://fbtricks.cf/
And It's Hosted in Hostinger.in
M Using PHP Extension, Because M Using a Common Header and Footer For All Files.
The Problem Is, I Have Made Changes to The Header and Footer. But Still The CHANGE is Not Reflecting in All Files. :(
And It's Not Just an ISsue in My Browser, But in Every Browser, The Old Header and Footer is Displaying Except in The Index File.
I THINK THAT, MAYBE IT"S HAPPENING BECAUSE THE SERVER HAS CACHED THE FILES.
Plz Provide Me With a Solution, as It's a Serious Issue For Me and My Website and Also For Website Visitors.
header file Link - http://fbtricks.cf/header.php
I'm not sure if this .htaccess file can override the global settings in Hostinger.
.htaccess:
<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
I have flv files on my server which have changing content but not necessarily changing names.
I am having an issue whereby the flv files send headers which set the file to cache. As sometimes the same user may require the same file with different content later the files need to tell the browser not to cache them.
I have tried using something similar to PHP's header() command but when I run:
Curl -I myfile.com/file1.flv
The headers are still there.
Any help please?
I am not sure how you tried using PHP for this, it is apache which is processing and dispatching the file so best to start there.
Try the below:
1) Enable headers.load (headers module) on apache. Else wont work.
2) add below to .htaccess. This will capture file types of all the below formats and set them not to cache.
<FilesMatch "\.(jpg|gif|js|css|ico|swf|zip|pdf|doc|htc|xls|rtf|odt|wav|mp3|avi|wmv|mov|txt|flv)$"> FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</IfModule>
</FilesMatch>
3) restart apache.
4) Try 'curl -i www.url.com/file.flv' command again.
You should see the headers tell the file to not cache.
when I am debugging to ensure that some files are not cached and therefore reloaded anew each time, I frequently link files with something like
<script src="script/js.js?<?=time()?>"></script>
Is there some way I can do something in css to ensure background images are reloaded every time the page loads without making the style something other than a .css file? (php with css header for example)
#bg_div{
background: url(../images/darrow.png.....)
}
Thanks!
You could use .htaccess like this:
<filesMatch "\.(gif|jpg|png)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Mon, 26 Jul 1990 05:00:00 GMT"
</ifModule>
</filesMatch>
This prevents all images to be cached. If you put the .htaccess file in a specific folder then images in this folder doesn't get cached.
Note that on sites with heavy load cache control should be carefully planned. Using a htaccess directive like this can VASTLY affect page load times.