Help me to enable cache for text/html and php files

#1
How can I enable cache for text/Html and PHP files via Litespeed WordPress Plugin?
I have written expires headers [ExpiresDefault A172800] in htaccess file, but LiteSpeed is not honoring it.
Below are the codes:
# 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 A31536000
ExpiresByType image/x-icon A31536000
ExpiresByType image/vnd.microsoft.icon A31536000
ExpiresByType image/svg+xml A31536000

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

ExpiresByType video/ogg A31536000
ExpiresByType audio/ogg A31536000
ExpiresByType video/mp4 A31536000
ExpiresByType video/webm A31536000

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

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

ExpiresDefault A172800

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

serpent_driver

Well-Known Member
#2
mod_expires doesn't control cache for static sources. This is what you are looking for:

Code:
<FilesMatch "\.(jpg|jpeg|woff|woff2|png|gif|swf|ico|js|css|ttf|eot|ico|min.js|mp4|webm|svg)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
Add or change file types for your need.
 
#3
Thank you for the update. All my static assets are working fine.
I am seeking assistance for the following assets.

text/html && PHP files

Can you describe how can I change the above code to set cache-control for these assets to two days?
 
#7
Because the first load always takes time. I am using Stackpath CDN and by default, it enables 3600Secs for cache-control header. While in this time period, the sites load faster and TTFB is less than 30ms Globally.
But after 1hour, the cache expires and requests for HTML files and PHP files are being requested from the Origin server which gradually increases the request round-trip.
Hence, they suggested setting a cache-control header to 2Days.
So, I append the below code with the existing as shown above.

# 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

ExpiresDefault A172800

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


But it is not working?
 

serpent_driver

Well-Known Member
#8
Browser caching && Lscache && CDN for PHP is not a good idea if you have LScache.

If you have problems with long page load time for the first request and if you use LScache, there seems to be a bottleneck. In my mind you shouldn't use Stackpath CDN. Change your hosting provider or upgrade your server to a more powerfull one and check page load time again. If you have still problems use Cloudflare.
 
#9
Thank you for your assistance.
CDN: I have tried BunnyCDN, Cloudflare, KeyCDN, Sucuri, and finally settled with the stack path as I have seen the results literally.
Server: It's a VPS server (4Core, 4GB RAM) dedicated to this site only. Powered by Cloudlinux.
WordPress: Already optimized to the core as much as possible.

I hope that answered you.
Can you help in this regard?
 

serpent_driver

Well-Known Member
#12
You already use browser cache for PHP:

Code:
cache-control public, max-age=172800
But LScache TTL is very short, only a few seconds. Disable browser cache and increase LScache TTL
 
#13
So, the setting in htaccess file comes into effect. Great!

1. Can you help me with the step to change the LSCache TTL setting?
2. Can you help how to set "Expires header" in the response header?
 
#15
I have just changed hosting from hostinger to digital.. Wordpress is installed under level 1 folder on public_html or main domain...
My Lite speed cache is missed on my many sites. Also suggest How html or php manually created can be cached..

I am New to Lite speed server ....Pleas guide me.. ..
Please advice on the below .htaccess file... you can take a look on : https://usps-track.us

Code:
# 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]

### 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 ###

### marker DROPQS start ###
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga
### marker DROPQS 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! ##
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /usps/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /usps/index.php [L]
</IfModule>


<Files ".user.ini">
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
</IfModule>
</Files>

# END Wordfence WAF



# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /usps/
    RewriteRule ^/usps/wp-content/hostinger-page-cache/ - [L]
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP_COOKIE} !(wordpress_test_cookie|comment_author|wp\-postpass|wordpress_logged_in|wptouch_switch_toggle|wp_woocommerce_session_) [NC]
    RewriteCond %{DOCUMENT_ROOT}/usps/wp-content/hostinger-page-cache/$1/_index.html -f
    RewriteRule ^(.*)$ /usps/wp-content/hostinger-page-cache/$1/_index.html [L]
</IfModule>
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 5 minutes"
    ExpiresByType image/jpeg "access plus 5 minutes"
    ExpiresByType image/gif "access plus 5 minutes"
    ExpiresByType image/png "access plus 5 minutes"
    ExpiresByType text/css "access plus 5 minutes"
    ExpiresByType application/pdf "access plus 10 minutes"
    ExpiresByType text/javascript "access plus 5 minutes"
    ExpiresByType image/x-icon "access plus 30 minutes"
    ExpiresDefault "access plus 3 minutes"
</IfModule>
 
#17
Thanks for your too prompt feed back @serpent_driver

Browser caches is already disabled ... But error i found later was migration and hostinger provide cache module as must plugin to use..anyway
i just removed the following codes few minutes back which hits caches.
Code:
 RewriteCond %{DOCUMENT_ROOT}/usps/wp-content/hostinger-page-cache/$1/_index.html -f
 RewriteRule ^(.*)$ /usps/wp-content/hostinger-page-cache/$1/_index.html [L]
 
#18
Please find the codes below:
# 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]

### 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 ###

### marker WEBP start ###
RewriteCond %{HTTP_ACCEPT} "image/webp" [or]
RewriteCond %{HTTP_USER_AGENT} "Page Speed"
RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]
### marker WEBP end ###

All static assets in the Wp-content folder is cached for one hour and Litespeed plugin again tries to re-cache everything huh..
If it does so, how can I increase the value of caching assets for a long period instead of 3600..
 

serpent_driver

Well-Known Member
#19
Cache lifetime for static sources is controlled by cache-control header in .htaccess or WP settings and cache for static sources will be cached by browser and not by LiteSpeed. That is not a LiteSpeed feature. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

[E=cache-control:max-age=3600] means the overall lifetime when it will expire. If expired LiteSpeed sends a new status code to the client, but if you want to increase cache lifetime for static sources use cache-control header like:

Apache config:
<FilesMatch "\.(jpg|JPG|jpeg|woff|woff2|png|gif|swf|js|css|ttf|eot|ico|js|mp4|webm|svg|json)$">
Header set Cache-Control "max-age=31536000, public, no-transform"
Header set Vary Accept-Encoding
</FilesMatch>
or set it in WP backend.

If you have further questions use: https://www.litespeedtech.com/support/forum/threads/please-use-the-official-wordpress-forum.16028/
 
#20
For Browser Cache, we have already set "Browser Cache to 31536000". Refer to the first conversation of this thread.
But my query is to understand the meaning of the above configuration and in particular the below ones.

### 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 ###
 
Top