How can I stop Joomla (Apache) from caching the admin backend? - apache

I've a big cache issue with my Joomla 1.5.26 (Apache/2.2.14 Ubuntu) administrator panel.
Everything is cached for about 15 minutes, and by everything I mean everything.
If I go to global configuration and change any value there, for example the Site Name from "MyTestSite" to "MyTestSite2", or the Feed length from 15 to 30 and save it a message is displayed that everything was saved and the cache was cleaned. If I go immediately to the global config again, I see that the old values (MyTestSite and 15) are still there. If I look into configuration.php I see that the file was correctly changed. Also, if I wait 15 minutes I can see the correct value. This is not related only to configuration, but even to article editing!
It's the same on 2 computers, and with Firefox, Chrome, and IE.
I've tried to fix it by placing a .htaccess in /admistrator/ to disable any caching, but to no avail.
I've tried this:
<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>
or this:
ExpiresActive On
ExpiresDefault "access plus 1 minute"
What is going on here? (it was working fine for 2 years). How can I stop Joomla from caching the admin backend?

Related

Caching issue with Apache; css and html not updating

I've recently setup a vps on Ubuntu 20.04 to host a single website amongst other non-apache related things. I've been attempting to work on my site but it seems that the files are being cached. For instance, I can still access the webpage and stylesheet even though its been deleted. Thus far I've spent a couple hours searching for a solution to this. I've looked through here, this and this. I've also tried the suggestion of one place in adding to my .htaccess as follows:
#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>
After adding that, restarting apache but still with no success. I've found other posts seemingly with the same issue as me which talk about editing 000-default.conf but I lack the technical understanding of apache to be able to make informed choices on editing things like that out of fear of breaking something.
I believe that apache caching is my issue but I could well be wrong. I can't think of what else it would be though. I think this is an issue I've had in the past but I don't remember the solution. Thanks for any help
Adding ?v=1.x.x to the end of the stylesheet URL fixed the issue. Credit to a Reddit user here

The files served by my Apache Server are not being saved on browser cache

I have installed and configured an Apache server with a virtualhost which serves images.
When I load my page with images on the browser the second time (the images should be on cache after the first time the page is loaded), the browser doesnt get the images (or files) from cache, and think that it should.
What is wrong? I am using Google Chrome, and when I load some other web from other server the cache works, so I think that I have some problem with the Apache, but I am not sure.
Thank you very much.
The response is a video-segment which is played by Dash player.
Response headers:
accept-ranges:bytes
content-length:194431
date:Wed, 09 Mar 2016 07:42:07 GMT
etag:"2f77f-52acd33f8b167"
last-modified:Tue, 02 Feb 2016 17:55:12 GMT
server:Apache/2.4.18 (Unix) OpenSSL/1.0.2e PHP/7.0.2
status:200
After doing that:
ExpiresActive On
# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(mp4|m4s)$">
ExpiresDefault "access plus 3600 seconds"
Header set Cache-Control "public"
Header set Content-Type "video/mp4"
Header set Vary "Host"
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
The headers are:
accept-ranges:bytes
access-control-allow-origin:*
cache-control:public
content-length:194431
content-type:video/mp4
But it doesnt save on the cache, I mean, when I reload the web or the video, it does not get it from the cache as it should.
You are not including any cache-control headers telling the browser to cache the resources. The spec is unclear how to handle this but most browsers choose not to cache unless explicitly told to.
You need to include Apache config like this (assuming you are already including the mod_expiries module):
ExpiresActive On
# Set up caching on media files for 1 week
<filesMatch ".([iI][cC][oO]|[gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[pP][nN][gG]|[fF][lL][vV]|[pP][dD][fF]|[sS][wW][fF]|[mM][oO][vV]|[mM][pP]3|[wW][mM][vV]|[pP][pP][tT])$">
ExpiresDefault A604800
Header append Cache-Control "public"
</filesMatch>
# Set up caching on font files for 6 months
<filesMatch ".([eE][oO][tT]|[tT][tT][fF]|[sS][vV][gG]|[Ww][Oo][Ff][Ff]|[Ww][Oo][Ff][Ff]2)$">
ExpiresDefault 15552000
Header append Cache-Control "public"
</filesMatch>
Which will then produce a header like this:
cache-control:max-age=10800, public
I've written a blog post on this if you want more details: https://www.tunetheweb.com/performance/http-performance-headers/caching/
OK, I have solved the problem.
I was using an https connection and the certificate I was using didnt have the correct parameters (common name must be the name of the url programmed on the server) and the certificate of the server must be authenticate by some CA, so I have made CA certificates to authenticate the server certificates. This means that if you have an unsecure https connection, Chrome does not save files on cache.
After having all the certificates corrected, I have upload to google chrome the certificates to trust my web (configuration of google Chrome, advanced options, Manage https/ssl certificates). After that, I can save files on cache because of the certificates which makes the https connection secure (green lock on the chrome url bar).
That was my problem and this is how I solved it.
Thanks for your answers and your time!! ;)

Apache: set max-age or expires in .htaccess for directory

I have a handful of directories with content which will never change.
Is it possible to create .htaccess file which tells the browser that anything in this directory and sub- directories can be cached for a very long time?
I would like to copy the same .htaccess file in each directory if possible.
If this is possible would you recommend max-age over expires or both?
So it does look possible.... the .htaccess file syntax is:
Header unset Last-Modified
FileETag none
ExpiresActive On
ExpiresDefault "access plus 1 years"
This will turn off Etags and turn on cache-control: max-age
Then put this .htaccess file in the directory and all files (including it's sub-directories will be cached for 1 year.
I decided to put all my cache-able content under a single root directory and edit the httpd.conf as
<Directory "C:\somedir\cache">
Header unset Last-Modified
FileETag none
ExpiresActive On
ExpiresDefault "access plus 1 years"
</Directory>
I am still in the process of testing this. I just hope this does not turn off Etags for the rest of the site. So far it looks like it's working as planned.
UPDATE (after 6 months):
Setting the ExpiresDefault and allowing e-tags is the best thing to do.
in httpd.conf:
<Directory "C:\somedir\cache">
ExpiresActive On
ExpiresDefault "access plus 1 year"
</Directory>
Make sure "somedir" is inside of the apache root (such as htdocs).
Allowing e-tags is a good because after 1 year, the browser will re-validate the file by passing the e-tag. The web server will send back a 304 - Not Modified and reset the max-age to 1 year. This is very efficient.
All in all, you can watch the apache log file and see that items in /cache dir are begin served once.
Note: I have found that setting Header append Cache-Control "public" is ok to do if you want.
Final Version:
Here's the final version: (just add this at the bottom of the httd.conf)
<Directory "C:\somedir\cache">
ExpiresActive On
ExpiresDefault "access plus 1 year"
Header append Cache-Control "public"
</Directory>
Inspecting the header should reveal this:
Accept-Ranges:bytes
Cache-Control:max-age=31536000, public
Connection:Keep-Alive
Content-Language:en
Content-Length:746
Content-Type:text/css
Date:Thu, 29 May 2014 15:23:50 GMT
ETag:"240000000add63-2ea-4f4086d72ad01"
Expires:Fri, 29 May 2015 15:23:50 GMT
Keep-Alive:timeout=40, max=200
Last-Modified:Fri, 07 Mar 2014 18:28:59 GMT
This will:
Set the max-age for 1 year (the longest recommended)
Send the expires tag of 1 year
Send an Etag, so after 1 year the browser will perform etag validation
Let intermediate caching devices/services know that they can cache the file for 1 year.
FYI, if you do what is mentioned above and your Apache won't restart then you may be getting this error:
The Apache service named reported the following error:
>>> Invalid command 'ExpiresActive', perhaps misspelled or defined by a module not included in the server configuration.
You can find that error by clicking "Start", type in "Computer Management", launch it, in the tree open "Event Viewer -> Windows Logs -> Application". That's where I found the error above.
Easy fix, just uncomment this line in httpd.conf:
#LoadModule expires_module modules/mod_expires.so

mod_expires sending Cache-Control headers for 3## status codes

Apache is sending Cache-Control headers for 3## status codes, like 302 redirects. This is causing Firefox (possibly starting with Firefox 5) to cache the 302 redirects--which results in an infinite redirect loop for some of my pages.
Here are the settings that I am using in my httpd.conf:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
</IfModule>
If I remove the ExpiresDefault setting, the problem goes away, so I am confident that this is the exact setting that is causing the problem. If I change ExpiresDefault A600 to ExpiresByType text/html A600 the problem is still there.
I'd like to have browsers cache my content by default, but this is a deal-breaker.
Are there any settings I can use to tell Apache to send a different Cache-Control header for 3## status codes?
If you add the Cache-Control headers in your application, which builds the redirect, apache will not overwrite it.
Cache-Control: max-age=0
Expires: Sat, 04 Feb 2012 07:02:38 GMT
if you use apaches mod_rewrite to do the redirect you could add the headers with the
mod_headers module.

Can browser display objects from its cache without receiving a 304 status code?

I'm trying to understand if is it possible to avoid request for some embedded objects, loading them directly from cache without asking to web server if the object is valid or not (i don't want web server response to me with 304 http status code) Is it possible ? Does the expire header works for this way? How?
Of course: Request:
<script scr="my_js.php"></script>
Response:
<? header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 31 Dec 2035 12:00:00 gmt");
header("Cache-Control: max-age=".(60*60*24*365));
echo "//this is a simpe example"; ?>
Solved
Browser loads resources from his cache without asking them to the web server only the first time you open the page (new tab or new browser window).
The other times browser ALWAYS ask information to the server about the resources saved in his cache. Then, the web server response with 200 or 301.
Yes, setting a distant expiry header and the asset will not be downloaded again until that expiry.
If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!
Source.
From my htaccess ...
<IfModule mod_headers.c>
Header unset Pragma
FileETag None
Header unset ETag
# cache images/pdf docs for 10 days
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|js)$">
Header set Expires "Mon, 31 Dec 2035 12:00:00 gmt"
Header unset ETag
Header unset Last-Modified
</FilesMatch>
# cache html/htm/xml/txt diles for 2 days
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
</IfModule>
it seems doesn't works .... for example firebug's net panel show me always 200 status code and access.log file report me that external objects are always requested by the browser.