Search code examples
htmlcachingtypo3browser-cacheclient-side

Typo3 8.5 - Enable client-side caching


I'm trying to enable client-side caching on my website powered by Typo3 8.5.3.

I have found this page : https://typo3.org/documentation/article/using-cache-control-headers-in-typo3/

But i can't manage to make it work.

These are my settings, am I missing something?

config {
   no_cache = 0
   sendCacheHeaders = 1
   cache_period = 86400
   cache_clearAtMidnight = 1
}

I've included this on a template use in my website but it doesn't seem to work. I don't know if it's a matter of server configuration or only Typo3 configuration.

I want to enable client-side caching to meet google's recommendations on his "speed test" : https://developers.google.com/speed/pagespeed/insights/

Here is a current header I get on a js file :

Date    Mon, 25 Sep 2017 14:01:18 GMT
Server    Apache
Last-Modified     Mon, 17 Jul 2017 07:13:51 GMT
ETag         "224cf4-20976e-5547e24169863"
Accept-Ranges       bytes
Content-Length      2135918
Content-Security-Policy     default-src * ; style-src * 'u…'unsafe-inline' 'unsafe-eval'
X-WebKit-CSP       default-src *; style-src * 'un…'unsafe-inline' 'unsafe-eval'
Content-Type      text/javascript
Strict-Transport-Security       max-age=31536000
X-XSS-Protection       1; mode=block
X-Content-Type-Options      nosniff

Solution

  • You can control the expiration dates by adding the following config to your .htaccess (you might have to add/remove some config to match your exact criteria but the pattern should be clear):

    ExpiresActive On
    ExpiresByType image/gif "access plus 1 week"
    ExpiresByType image/jpeg "access plus 1 week"
    ExpiresByType image/png "access plus 1 week"
    ExpiresByType image/svg+xml "access plus 1 week"
    ExpiresByType text/css "access plus 1 week"
    

    This does set the expire times to 1 week for the given file mimetypes. As said you maybe have to adjust which file mimetypes are controlled to get rid of all your warnings.