WpW: Using Browser Cache in LSCache

Written by

in

Welcome to another installment of WordPress Wednesday!

Today we are going to talk about another enhancement to the LSCache plugin for WordPress: Browser Caching! We’ll talk a little bit about how browser caching is different than page caching (LSCWP’s specialty), but if you’d like a more in-depth exploration of the topic, you should take a look at our Caching 101 series.

Why Browser Caching?

LiteSpeed Cache is a full-page cache. It takes expensive-to-generate dynamic content and stores it as easy-to-serve static files. While it handles dynamically-generated content well, it only handles dynamically-generated content. Static content such as images, video, or fonts is not included in a page cache. And yet, this content may be requested from the server repeatedly. Take, for instance, your site’s logo. That image is likely to be displayed on every page that the user visits, which means the server has to transfer that same image to that same user, over and over and over again.

This is where browser caching comes in handy. With browser caching enabled, your logo (along with other static content) is stored locally on the user’s device the first time it is requested. After that, the content is pulled from the device’s local storage until the browser cache expires. Displaying a local image will always use fewer resources than transferring an image across the internet, no matter how fast your connection may be.

How to Set it Up

Normally, browser caching is enabled at the LiteSpeed Web Server level. However, if you do not have access to your server’s admin, you can still enable browser caching through the LSCWP plugin settings. You can choose to set this up at whichever level makes the most sense for your site(s).

If browser caching is turned on at any level (server, plugin, or both) then it will be enabled.

At the Plugin Level

From the WordPress Dashboard, navigate to LiteSpeed Cache → Settings → Advanced and scroll down to Browser Cache.

Set Browser Cache to ON.

That’s it! Browser caching will now be enabled for your site. Most static files will be cached locally on the user’s device, and will expire after one month.

At the Server Level

If you are a server admin, you have somewhat more control. In the LiteSpeed Web Server Admin, navigate to Server > General and scroll down to Expires Settings.

Set Enable Expires to Yes.

Expires Default may be set to a number of seconds or left blank if you don’t wish to provide a catch-all expiration.

Set Expires by Type to a string similar to the example shown, changing any file types or expiration times as desired. The example enables browser caching for all images, css, and javascript, and it sets all of their expirations to 604800 seconds (or one week). If you leave Expires Default blank, then you must specifically include every file type you want cached by the browser in Expires by Type.

NOTE: Do not set a text/html Expires by Type, because that will interfere with LSCWP’s page cache.

Once you have enabled browser caching using one of the above methods, your visitors should experience a performance boost, particularly if your site is image-heavy, or contains a large amount of other static files. Just remember, a browser cache operates like every other cache does: it needs to be populated before your users will see any benefit. So, the first time a visitor requests a page on your site, all of the static assets will still need to be transferred over the internet. For subsequent visits, any static files that have already been requested will now be available locally on the visitor’s device until they expire.

If you have any questions or suggestions regarding this new feature, let us know in the comments section!

Have some of your own ideas for future WordPress Wednesday topics? Leave us a comment!

Don’t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:

Comments

7 responses to “WpW: Using Browser Cache in LSCache”

  1. Neil Gowran Avatar

    In case anyone can’t find it – looks like the Browser Cache option is now in the Advanced Tab

    1. Lisa Clarke Avatar
      Lisa Clarke

      Correct. It has moved. Thank you for the update.

  2. H.M. Gomez Avatar
    H.M. Gomez

    Your plugin has broken my page! How can I undo this again. All pages now show only old content, even after clear cache etc.

    ## EXPIRES CACHING ##

    ExpiresActive On
    ExpiresByType image/jpg “access 1 year”
    ExpiresByType image/jpeg “access 1 year”
    ExpiresByType image/gif “access 1 year”
    ExpiresByType image/png “access 1 year”
    ExpiresByType text/css “access 1 month”
    ExpiresByType text/html “access 1 month”
    ExpiresByType application/pdf “access 1 month”
    ExpiresByType text/x-javascript “access 1 month”
    ExpiresByType application/x-shockwave-flash “access 1 month”
    ExpiresByType image/x-icon “access 1 year”
    ExpiresDefault “access plus 1 month”

    ## EXPIRES CACHING ##
    # BEGIN LSCACHE
    # END LSCACHE
    # BEGIN NON_LSCACHE
    # END NON_LSCACHE

    1. Lisa Clarke Avatar
      Lisa Clarke

      I’m sorry to hear you’ve had a bad experience with our plugin! We’d like to help you make it work.

      I can’t say for sure what is happening, just from that small snippet of code, but this line is definitely a problem:
      ExpiresByType text/html "access 1 month"

      Change it to:
      ExpiresByType text/html "access plus 0 seconds"

      That line is causing all pages to be cached by the browser, which essentially bypasses all of the benefits of LSCache, and can lead to stale content. You can learn more about that on our wiki, if you like. I’m not sure where that line came from, but LSCache would not have added it.

      If this doesn’t solve the problem, please create a ticket through our client area or by sending email to support@litespeedtech.com. We’d like to help you figure out what went wrong.

  3. Birdbrain Solutions Avatar

    Hi,

    Firstly, thank you for creating the plugin, I love it and recommend it to everyone I know! 🙂

    Secondly,

    I cannot find the browser cache option: https://i.imgur.com/XTVP2f4.jpg

    It was already enabled at the server level when I went to check it, but it’s not showing : https://i.imgur.com/icjQzsl.jpg

    Please help, thank you!

    yours sincerely,

    Nick

  4. Birdbrain Solutions Avatar

    Never mind, I found it!

    I was searching in the Cache tab after clicking advanced 🙂

  5. ali ft Avatar

    thanks, i used it ^ _ ^
    I always come to your site

Leave a Reply

Your email address will not be published. Required fields are marked *