[Solved] Browser caching only for 3 seconds

#1
I have enabled browser caching in the plugin, but it seems to only be caching css files for 3 seconds according to gtmetrix.

I have not changed the default timeouts, so the browser cache TTL is set to 2592000
 
Last edited by a moderator:
#3
here is the content of my .htaccess
I checked the backups created by lscache, and none of these entries were there prior to installing lscache.

Apache config:
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule ^min/\w+\.(css|js) - [E=cache-control:no-vary]

### marker CACHE RESOURCE start ###
RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###

### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker FAVICON end ###

</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
### marker BROWSER CACHE start ###
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType application/pdf A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType image/vnd.microsoft.icon A2592000
ExpiresByType image/svg+xml A2592000

ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/webp A2592000

ExpiresByType video/ogg A2592000
ExpiresByType audio/ogg A2592000
ExpiresByType video/mp4 A2592000
ExpiresByType video/webm A2592000

ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000

ExpiresByType application/x-font-ttf A2592000
ExpiresByType application/x-font-woff A2592000
ExpiresByType application/font-woff A2592000
ExpiresByType application/font-woff2 A2592000
ExpiresByType application/vnd.ms-fontobject A2592000
ExpiresByType font/ttf A2592000
ExpiresByType font/woff A2592000
ExpiresByType font/woff2 A2592000

</IfModule>
### marker BROWSER CACHE end ###

### marker MINIFY start ###
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} ^(.*)/min/(\w+)\.(css|js)$
RewriteCond %1/wp-content/cache/$2/$1.$2 -f
RewriteRule min/(\w+)\.(css|js) wp-content/cache/$2/$1.$2 [L]
</IfModule>
### marker MINIFY end ###

## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
# BEGIN LiteSpeed
<IfModule Litespeed>
SetEnv noabort 1
</IfModule>
# END LiteSpeed
 
Last edited by a moderator:

NiteWave

Administrator
#4
if it's a WHM/cPanel server, please check if there is any "cache-control" in /etc/apache2/conf.d/includes/*. i.e.
Code:
grep -i cache-control /etc/apache2/conf.d/includes/*
 
Last edited by a moderator:
#5
This is shared hosting, I do not have access to server settings.
I do however have multiple sites on the same host/plan which do not have this issue.
 

NiteWave

Administrator
#8
Code:
# curl -I https://staging.eosrooflights.co.uk/min/97f30.css
HTTP/1.1 200 OK
Cache-Control: max-age=3, must-revalidate
Expires: Sat, 17 Aug 2019 02:53:54 GMT
Last-Modified: Wed, 17 Jul 2019 17:55:14 GMT
Content-Type: text/css
Content-Length: 2982
Accept-Ranges: bytes
Date: Thu, 18 Jul 2019 02:53:54 GMT
Server: LiteSpeed
Vary: Accept-Encoding, Cookie
Alt-Svc: quic=":443"; ma=2592000; v="35,39,43,44"
Connection: Keep-Alive
Cache-Control: max-age=3, must-revalidate is the culprit.
it must be set somewhere manually, web server won't set it automatically.
 
Last edited by a moderator:
#11
Hi,

I believe I have tracked this down.

Looking at the .htaccess in the document root it can be seen that the Litespeed cache plugin is configuring minified assets to be sourced from the WP cache directory.

/home/eosrooflights/staging.eosrooflights.co.uk/.htaccess:
Apache config:
### marker MINIFY start ###
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} ^(.*)/min/(\w+)\.(css|js)$
RewriteCond %1/wp-content/cache/$2/$1.$2 -f
RewriteRule min/(\w+)\.(css|js) wp-content/cache/$2/$1.$2 [L]
</IfModule>
### marker MINIFY end ###
In that directory is another .htaccess in which the 3-minute age directive is configured.

/home/eosrooflights/staging.eosrooflights.co.uk/wp-content/cache/.htaccess:
Apache config:
<IfModule mod_headers.c>
  Header set Vary "Accept-Encoding, Cookie"
  Header set Cache-Control 'max-age=3, must-revalidate'
</IfModule>
Does LSCACHE create this file?
 
Last edited by a moderator:

Pong

Administrator
Staff member
#12
I believe LiteSpeed plugin never did that. all Litespeed cache plugin browser cache configuration should be found directly in plugin and wrote to document root .htaccess.

However it is good you locate the root cause and you can simply comment them out.
 
Top