Hi,
Loving the new version of Flag! I have moved over from session favorites and found the configuration very quick yet powerful and flexible. Great module!
So, I am planning to have 2 Flag related blocks on the front page:
* One block on the front page will show a view-list of node-teasers including the "Add to Favorites" link (if this is already in favorites it will say "remove from favorites"
* Another block will show a views-list of Favorites (Flagged nodes) for the current anonymous user.
I read that Flag 2 works with Page Caching! Sounds great, wondering how it works and if my second views-based block will also work with page caching.
In general do you have any tips to optimize performance when anonymous users can see different versions of the page?
Comments
Comment #1
quicksketchFlag does this by always showing the same (non-flagged) state when the page loads, then uses JavaScript to replace with the flagged version of all links on the page.
Unfortunately showing a listing of flagged content is outside the capabilities of Flag. Flag only flips back and forth the "flag this" links for anonymous users, it doesn't make it so that Views can work with page caching for anonymous users. You're given a warning when you configure a View to show flagged content for anonymous users that it will disable page caching when viewed. So if you were to put this kind of listing into a block, it'd essentially disable page caching.
Comment #2
JimNastic commentedHi quicksketch,
Thanks for the super-fast response!
In that case, do you think it would make sense to simply display an empty (or placeholder) block with page load and always fetch the view by javascript after page load and whenever there is an flag change?
Comment #3
quicksketchI'd probably suggest you have something like "My list (2)", where "2" is the number of items that has been flagged. Then you can view the list on a dedicated page (think like the way most shopping carts work). You'll have to do some custom JavaScript to insert the number of items by checking the user cookies for the flagged list.
There's also the possibility of using an iFrame like you've suggested, but then you'll be doing two page requests (one cached and one not cached) per page viewed, which may just end up hurting you more than helping. It depends on what kind of caching software you have on your server (i.e. Varnish) that would determine if that approach is helpful or not.
Comment #4
JimNastic commentedHi Quicksketch,
Thanks for the tips. I think I will first try with the flag block, without page cache, and see if performance is OK. If it is a problem, then I will fall back to your suggestion.
One last question.. I have some views which add the flag as a relationship and add the flag-link as a content item so that site visitors can add nodes to their favorites list from the teaser, without going to the node page. As I create the view, it tells me this also disables page cache. Is that your understanding? In that case is it that the only use of the link which preserves the cache is on the node page. True?
Thanks again,
Jim
Comment #5
mooffie commentedThere's now a handbook page discussing this subject:
Technical notes about "anonymous" flaggings when page caching is turned on.
So I'm closing this issue.
Thanks for reporting this. The handbook now mentions this. That warning was changed to be more accurate.
(Whatever, use "dev" if you're interested in anon+cache. "beta4" is too buggy in that.)
Comment #6
JimNastic commentedThanks! A really useful page! I'll use several of those tips!
Merry Xmas!
Jim