• Resolved jlahm

    (@jlahm)


    I am very intrigued that the new ESI capability may help with a couple problems I have related to changes to the home page appearance depending on whether a user is logged-in or not. On our site, we have a login block on the home page that allows the user to login/logout. Once logged in, we change the wording to say something like “Welcome John Doe”. In addition, in another block on the page we add additional links that are only available to logged-in users. Finally, the main menu is also changed to include some new menu items, again only for logged-in users. I am using public and private caching.

    My question: Does ESI only work with widgets, or can I use it for the menus and for other blocks of text? I have found (but not tested) a plugin that allows a widget to be placed in a block of text, so that has promise. But I haven’t figured out what to do about the menus. As it is on the front page, I’d love to have the caching enabled as the performance increase is noticeable.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support Hai Zheng?

    (@hailite)

    Yes ESI can work with widgets. Once you turned on ESI, you will see the options in widget setting page. If that widget includes private info or something that guest shouldn’t see, set it to private.

    For you admin bar, it should be fine, as admin bar is always private.

    For the block on your homepage which will show different content for different users, if it’s a widget, it will be easier as you can directly set private. If not a widget but part of the homepage template in theme, you need to call LiteSpeed_Cache_API::esi_url() to punch hole and make it an ESI block (this way your homepage can still be public, which will be shared between logged in users), and then use LiteSpeed_Cache_API::hook_tpl_esi() to hook to the second http request to display your private info.

    Thread Starter jlahm

    (@jlahm)

    That response was fast!

    Will the approach using the API calls also work with my main menu (the admin bar isn’t an issue for me)? If so, I guess I would have two define two main menus – one for public user and one for private?

    Plugin Support Hai Zheng?

    (@hailite)

    in your second ESI request handler, yes you should have two:

    1. For guest users, show please login. (public)
    2. For logged in users, show Hi Tim. (private)

    • This reply was modified 7 years, 5 months ago by Hai Zheng?.
    Thread Starter jlahm

    (@jlahm)

    Also, where might I find any documentation/examples for those two API calls?

    Plugin Support Hai Zheng?

    (@hailite)

    Thread Starter jlahm

    (@jlahm)

    I think I may have confused things. The suggestions you made in your initial response apply nicely to my problem with embedded text on the page that changes based on the login status. I am also trying to see if this same approach would also work for the website’s main menu (which also varies based on login status). This is where I was wondering whether I had to define two WordPress menus and show one or the other based on public/private.

    I hope that makes sense! Thanks so much for your help. I will take a look at the API documentation, although at first glance those items you specified (esi_url() and hook_tpl_esi()) are not mentioned.

    Plugin Support LiteSpeed Lisa

    (@lclarke)

    @jlahm

    Do both menus contain only public information? (i.e. there is no individualized content?)

    If both menu variations can be publicly-cached, then this sounds like a situation for “vary groups.” You can learn more about how vary groups work in our recent blog post.

    So, for your situation, you have logged-in users, and each of them is assigned a particular user role. Let’s say all of your users are either “administrator” or “subscriber.” When you set up a vary group, set both of those roles to the same number (it can be any non-zero number).

    Then, a public copy of the page will be cached for administrators and subscribers, and another copy will be cached for everyone else. Each will have the appropriate menu (assuming your site is already set up to correctly generate the different menus, of course).

    Does that make sense?
    Please let me know if you need clarification on anything!

    Lisa @ LiteSpeed

    Thread Starter jlahm

    (@jlahm)

    Yes, this explanation of using the “vary groups” helps a lot. I will look into it.

    I believe a large part of my problem was me. ?? Understanding the difference between public versus private caching, ESI and vary groups is one thing, but knowing when and why to use them is another. I wanted to have some portion of the home page to contain a note like “Welcome John Doe”. It appears I can do that using either a private cache or by using ESI. The advantage of the private cache is that it is easy! But, it isn’t pre-populated and the user will benefit from the cache only for those pages that they revisit. The advantage of the ESI approach is that I can take advantage of a pre-populated public cache and simply replace a small portion with my “Welcome John Doe” text. The vary groups solves my problem of having two different menus, but does not allow me to put the custom text on the page. I hope all of that is correct!

    I am leaning towards removing the custom text and using vary groups. One issue with the ESI approach is the lack of a good example. A previous A2 reply in this thread pointed me to an API document, but the commands he suggested I use weren’t in there. Having an example of “punching a hole” to display or hide a block of text would be really useful.

    Thanks so much for the help! I am really impressed with the LiteSpeed plugin and the upcoming updates that have been mentioned elsewhere.

    Plugin Support LiteSpeed Lisa

    (@lclarke)

    Actually, you can still have ESI blocks on the pages that are cached as vary groups. So, you can have two copies of the publicly-cached full page, and each of those copies will also have an ESI block for the welcome message.

    Nice, right? ??

    Plugin Support LiteSpeed Lisa

    (@lclarke)

    @jlahm I replied so quickly, I missed big sections of your post! Oops.

    So, you asked for an example of punching a hole. Have you seen our blog post about ESI? It has a few examples that should help you, but really, what you want to do with a greeting is a *classic* application for ESI. It’s the perfect example.

    You wouldn’t want to use a full-page private cache for just that one little bit of text. Despite the issue of prepopulation that you mention, it also takes a lot of resources to store private cache. Think: a separate copy of the page for each person who visits your site. That can grow quickly!

    Don’t be too hard on yourself for not immediately getting how and where to use each type of cache. It can be confusing at first!

    Let me know if you need me to dig up some more examples for you!
    Lisa

    Thread Starter jlahm

    (@jlahm)

    Great! Yes, I’ve seen the blog post and realize I can do it using a widget. So, I was planning to see if I can place a widget into a portion of the front page.

    By wanting an example, I should have been more specific. The earlier reply suggested adding some code to the page to accomplish this. I was looking for an example of PHP code to accomplish this and thought it might be something others could benefit from (not just an old retired geek like me). ??

    Thanks so much for your help! A2 support has been great – and patient – explaining things.

    Plugin Support LiteSpeed Lisa

    (@lclarke)

    Ah! Yes, I understand now. And you are correct – it looks like the documentation was never updated when the ESI functions were added to the API. I’m afraid I can’t give you any examples off the top of my head since this is the first time I’ve seen them, but after I’ve had a little bit of time to dig into those functions (and update the documentation), I’ll be able to speak more intelligently about how to use them ??

    In the meantime (and I apologize in advance if this is too basic), this article I came across explains functions, filters, and hooks for beginners and is loaded with generic examples.

    Plugin Support LiteSpeed Lisa

    (@lclarke)

    Hi, @jlahm

    I’m going to close this topic due to inactivity, but before I do, I wanted to pass along this page in our wiki. It’s got a few examples that might help, if you’re still having difficulty.

    If you still need assistance, let us know!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Use ESI with logged-in users’ is closed to new replies.