fbpx

Optimizing caching performance in LiteSpeed Web Server

LiteSpeed Cache plugin on WooCommerce webshops

This code snippet can be used to optimize caching performance for a WooCommerce store running on a LiteSpeed server with the LiteSpeed Cache plugin for WordPress installed, helping to improve the speed and performance of the store for visitors. LiteSpeed is a high-performance web server that can handle a large amount of traffic and has built-in caching functionality to speed up the delivery of content to visitors.


    RewriteCond %{HTTP_COOKIE} banner
RewriteRule .* - [E=Cache-Control:no-cache]

RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule \.litespeed_conf\.dat - [F,L]
RewriteRule cms/wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga


ExpiresActive on
ExpiresByType application/pdf A31557600
ExpiresByType image/x-icon A31557600
ExpiresByType image/vnd.microsoft.icon A31557600
ExpiresByType image/svg+xml A31557600

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

ExpiresByType video/ogg A31557600
ExpiresByType audio/ogg A31557600
ExpiresByType video/mp4 A31557600
ExpiresByType video/webm A31557600

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

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

The code is divided into two blocks, LSCACHE and NON_LSCACHE, and includes several rules for caching different types of resources, setting cache control headers, and modifying cache keys.

The LSCACHE block is specific to LiteSpeed’s caching mechanism, and includes rules for setting cache control headers and modifying cache keys for specific types of resources such as responsive images, JavaScript files, and fonts. It also includes a rule for disabling caching when certain cookies are present, as specified by the “banner” cookie.

The NON_LSCACHE block includes rules for setting cache expiry times for different types of resources using the Expires header. This block is not specific to LiteSpeed and can be used with any web server that supports the Expires header.

In summary, this code snippet is useful for configuring caching for a WordPress site on a LiteSpeed server, with rules for optimizing caching performance for specific types of resources and setting cache expiry times for others.

Hire your codeartist

looking for a development of your own project?

is your agency looking for a partner?