I’m working on a social networking app where users can follow each other.
To speed things up I added fragment caching on users’ preview and full page views.
The good news is the app became really fast.
The bad one is that I started experiencing bugs related to follow buttons.
In fact all users preview and full page views have one follow block that can have different 4 states whether the user is logged in, seeing his profile, seeing someone else’s followed already or seeing someone else’s not followed already.
To address this issue I ended having a different cache version of each user’s preview and full page views in each of the 4 different states (= 8 different cached fragment for each user). The issue is now gone but I can’t help but think this is far away from being optimal.
Then I heard about Ryan Bates’ Railscast on dynamic fragment caching and started thinking.
Maybe I could load just the follow button through ajax. But then …
- Should I make one request for each button ?
- Should I gather them all up to prevent having a lot of requests ? How ?
- Is there a better way ?
What do you think ? 🙂
No, you should bundle them together, because it would be much faster than one request per button
Yes, you know all objects displayed on one page, so you should be able to collect all id’s of users to be followed and ask for their followed state.
Nothing that I can think of, but that doesn’t mean there isn’t a better way.