Support

Admin Tools

#28447 ##### Optimal default expiration time - BEGIN

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by bobpit on Friday, 15 September 2017 10:55 CDT

bobpit
Hi

I am examining the .htaccess file and I noticed those line:

>>>>>>>>>>>>>>>>>>>>>>>
##### Optimal default expiration time - BEGIN
<IfModule mod_expires.c>
# Enable expiration control
ExpiresActive On

# CSS and JS expiration: 1 week after request
ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"

# Image files expiration: 1 month after request
ExpiresByType image/bmp "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
ExpiresByType image/jp2 "now plus 1 month"
ExpiresByType image/pipeg "now plus 1 month"
<<<<<<<<<<<<<<<<<<<<<<<<<<

Questions:
1) Are those lines generated by Admin Tools?
2) How can I change the expiry of images, for example from 1 month to 3 months? I mean, not by editing the raw .htaccess file, but from some kind of UI or the .htaccess generator.
3) I noticed the .jpeg extention. Do I also need similar ExpiresByType statements for the .jpg .JPEG .JPG extentions ?

bobpit
According to my tests, the following command covers both jpeg and jpg filetypes:
ExpiresByType image/jpeg "now plus 1 month"

nicholas
Akeeba Staff
Manager
1) Are those lines generated by Admin Tools?


Of course. You are using the .htaccess Maker. The entire file is generated by Admin Tools.

2) How can I change the expiry of images, for example from 1 month to 3 months? I mean, not by editing the raw .htaccess file, but from some kind of UI or the .htaccess generator.


You cannot. The expiration times are hard coded and are based on the recommendations by Google and Yahoo when they give you a performance ranking of your site. Please note that increasing the expiration time of media beyond 1 month is futile. Your visitors don't visit only your site and have a finite (and limited) amount of cache. Even an expiration time of 1 week is more than enough. You could set it to 1 month, 3 months, 1 year or 1000 years to the same effect: if they haven't visited your site for more than 3-4 days the content is no longer on their browser cache.

We could get away with using 1 week for the expiration time of CSS and Javascript without affecting performance rankings so we did exactly that. You might observe that text/html is not present in these lines. This is on purpose. HTML pages on a Joomla! site are dynamically generated and carry their own caching headers. If you add caching at the .htaccess level you'll have some interesting artifacts, like not being able to edit the same item twice in a row. So please don't touch these lines.

3) I noticed the .jpeg extention. Do I also need similar ExpiresByType statements for the .jpg .JPEG .JPG extentions ?


They are not extensions, they are MIME types. All JPEG files, no matter their extension (.jpg, .JPG, .jpeg, .someone_did_something_stupid) have the same MIME type image/jpeg. That's why you only get that line there. The next two lines are for other, more exotic, image formats.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

bobpit
Hi

Thank you very much for the reply.

1) Is there a way to turn off all these caches? In case I do not want anything cached in the user's browser?

2) I am mostly interested in using the Cloudflare cache, not the visitor's browser cache. So suppose I wanted to set
s-maxage = 1 month for my css files, where would I put this?

3) Ulitmately I want to cache SOME of my HTML pages that are key to my SEO, which I know that they change very rarely. for example those three pages:
https://mydomain.com
https://mydomain.com/page1.html
https://mydomain.com/page2.html

I want to cache them in Cloudflare cache, not the visitor's cache. I know the standard way of using CF pagerules for this, but I prefer to use htaccess (it is cheaper). Could you help me with this?

Thank you Nicholas

nicholas
Akeeba Staff
Manager
1. Yes, of course. Per the documentation you can simply disable the "Set default expiration time to 1 hour" setting.

2. I think you are misunderstanding how things work. Your site sends data to CloudFlare. CloudFlare delivers it to the browser. The caching headers sent by your site only determine how long CloudFlare will hold on to that data in its cache before it asks your server to deliver it again. The same caching headers will be passed to the browser. You, or CloudFlare, do not define what the browser will do with its cache. This is up to the browser. So what you ask is, of course, impossible because at the same time you want to have a fairly long caching time (for CloudFlare to work) and zero caching (for the browser to always request a new copy of the data).

Worse, even if that was possible it would completely beat the purpose of using cache control headers which is to make your site faster by having the client (browser) download less data from your server. What you describe would require the browser to reload every single asset (CSS, Javascript, images) on every single page load. This would be impossibly slow and ruinously expensive on metered connections (that's over 99% of mobile Internet connections). I don't think your site's visitors would like that.

3. This is unrelated to Admin Tools (or any other of our software) so I cannot answer this question. What you are looking for is a SEO extension (e.g sh404SEF) which lets you set a cache header per generated HTML page using a set of predefined rules. Apache, controlled through .htaccess, is not good at per-URL expiration rules. It's good for per-MIME-type rules.

Based on all your questions I recommend AGAINST using the "Set default expiration time to 1 hour" setting - which is a simple convenience feature for your average site. Admin Tools isn't meant to be an SEO solution; it's a security tool. So, instead of trying to abuse Admin Tools for something it's not designed for, please use the default caching options of CloudFlare for your static media and an SEO extension for customized, per-page expiration time for HTML pages.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

bobpit
Hi Nicholas

Thank you for the very detailed answer and recommendation.

2) I was talking about this:
Cache-Control: s-maxage=200, max-age=60

Taken from here:
https://support.cloudflare.com/hc/en-us/articles/202775670-How-Do-I-Tell-Cloudflare-What-to-Cache-

Anyway, I decided to use CF page-rules for this project.

Thank you again.

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!