Really stumped on this one.
I'm trying to cache some resources with the HTML5 cache manifest (yes, I know, don't judge me), but the manifest seems to be caching itself.
The manifest file is actually a dynamic PHP script, so it has a .php extension.
The following headers are set (How do I completely disable caching in Cakephp?)
header('Cache-Control: no-store, private, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0, max-stale = 0', false); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Expires: 0', false);
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Pragma: no-cache');
header("Content-type: text/cache-manifest");
The manifest contains the following in the NETWORK section:
NETWORK:
/cachemanifest
/cachemanifest/
/cachemanifest/*
*/cachemanifest/*
cachemanifest/
cachemanifest
/cachemanifest/manifest.php
cachemanifest/manifest.php
*
Of course, the manifest file itself is excluded from the CACHE: section.
There's also a .htaccess file in the same directory containing this:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>
The site is built with CakePHP, which apparently has some 'helpful' caching mechanisms that I don't know much about. I'd assume the PHP headers would bypass anything... PHP could do.
So, what am I missing?
Actually, it looks like one of these worked. It just takes 30+ seconds for the cache to realize that it needs to update.
The way cache manifests work is that for the manifest to update itself some text inside the manifest has to change, even if it's just one letter. This can be done by having a build automator add a timestamp every time there is a change in code.
Related
I'm still inexperienced as a web developer so I have exhausted my knowledge on my current problem.
I recently made changes to files on my one website and uploaded them via FTP to the server. When I go to the website it's still executing the old code.
I cleared all my cache and tried on different devices. Even after changing the file names for example "logout.php" to "logout_code.php" as well as link references to those names when I click on the logout button it still goes to "logout.php".
Can anybody shed some light?
Try setting a no-cache header on the page that redirects to the logout page.
header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
The above snippet goes at the top of the page before any other output is sent. (within a <?php ?> tag of course)
I have seen an error which seems extremely weird to me.
http://www.shrimadrajchandramission.org/grace/downloads/wallpapers/images/download.php?wp=SRM-Wallpaper-36-highres.jpg
On my browser, the above link shows 8.4 MB download file size
http://www.shrimadrajchandramission.org/grace/downloads/wallpapers/images/download.php?wp=SRM-Wallpaper-36-highres.jpg&
While this one shows 15.3 MB download file size.
I want to understand if the Server itself caches in some manner, because I had my Hard Disk Replaced recently so I have installed browsers on fresh OS, but it still shows the old filesize (and when you download it, half of it is corrupt-gray color).
download.php on the server has these Headers set:
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file_name)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: image/jpg');
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file_name));
I am now using a JavaScript Date Function to get the file afresh from the server. So my current issue is resolved, but I am trying to understand what is happening behind the scene.
If you are unable to reproduce this issue, then what could be the issue on my computer specifically? I have at least one person whom I know facing the same scenario.
Thanks!
I crete a web service in php and which returns JSON. It works fine but it seems to be cache results I changed values in the table and the service doesn't reflect this change. I included the following code but it doesn't seem to work. in my browser I am still getting the old values. How can this be rectified?
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
You may want to check your Ajax library (client) documentation see if you can disable its caching mechanism.
If you wish to disable cache on server side, refer to "How to control web page caching, across all browsers?"
I have a .htaccess in my root directory with the following setting.
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=864000, public, must-revalidate"
</filesMatch>
I thought it caches any of the files in the filesmatch directive. One thing that I am not clear about is whether the browsers cache the actual HTML content that goes out (from index.php) or not. I don't want browsers to cache the HTML. I only want browsers to cache the images, css and js.
Thank you.
From what you are saying you are uncertain if the browser is caching your PHP file or what is generated from it, use these headers to be absolutely certain, you will never know unless you are explicitly setting rules for it:
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
I've moved a older site to a new server, and the client has found a very odd behaviour.
Very close to the end, I have this code:
if (!$this->cache) {
header('Expires: '.gmdate('d M Y H:i:s', 946684800).' GMT');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
}
Now the odd thing is the Cache-Control line doesnt work.
After packet sniffing I see this:
Expires: 01 Jan 2000 00:00:00 GMT
Cache-Control: max-age=300, public
Pragma: no-cache
The order of the headers is exactly how I set them, but the Cache-Control is completely different. I've grepped my code for any mention of cache-control and there is only that mention, and another one designed to force caching in a different file but it is a different line to what I'm seeing so it cant be the culprit.
Does anyone know why Cache-Control is changing?
If you are using sessions, it's possible that PHP is overwriting them. Take a look at session_cache_limiter() in the manual.
Alternatively, you can try setting those headers after you call session_start().
(Edit: I missed the bit about "Very close to the end," so maybe this isn't your problem.)
I think you are running Squid, you should check its config for:
header_replace Cache-Control max-age=300, public