Web Hosting Knowledge Base / Website Hosting: How-To

How to enable LSCache on my website?

What is website Caching?

Web application websites (Like Wordpress, Laravel, ..etc) consist of dynamic pages that are built with PHP or some other method. The pages of such websites aren’t stored anywhere on the website itself; they are built on-demand by the web application, and then served to the website visitor as plain HTML. Generating these dynamic pages can be resource-intensive and slow.

LSCache is a "page cache." A page cache's job is to take this dynamically generated web page once requested, and store it as a static HTML snapshot, and next time the same page is requested by another visitor, the snapshot will be immediately served. Serving a snapshot is much faster and uses far fewer resources than generating the page dynamically does.

What is LSCache?

LiteSpeed Cache (or LSCache) is an efficient and highly customizable caching alternative to Apache mod_cache and Varnish. 

LSCache is built and integrated into LiteSpeed web server. It can dramatically speed up dynamic website content (like PHP pages), provide more efficient handling of static content (like images) and reduce server resources usage.

How to enable LSCache on my website?

If your website uses any of the following applications, then you can use the free Litespeed cache plugin specified for each one:

Otherwise, you can enable LSCache by inserting the following directive in the top of .htaccess file

CacheEnable public RewriteEngine On RewriteCond %{REQUEST_METHOD} ^GET|HEAD$ RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteCond %{REQUEST_URI} !login|admin|register|post|cron RewriteCond %{QUERY_STRING} !nocache RewriteRule .* - [E=Cache-Control:max-age=300]

Remember to replace example.com with your real domain name in line #4, if your website serves one domain then you can remove the entire line.

in line #5, you can add request URIs that you do not want to cache (you do not want to cache highly dynamic pages of your website like admin area.), if you want to cache your entire website then you can remove this line.

Verify if LiteSpeed Cache is working

You can use your browser Developer Tools to verify, the following short video will tell you how:


Or use online LSCache checker by Litespeedtech.

Last update: Jul 16, 2022 16:07