- Fragment caching
- use
belongs_to :parent, touch: true
to invalidate parent objects when child is modified - share cache between pages
- use CSS to modify fragment look
- use JS to modify fragment based e.g. on current user - e.g. hide "edit" button if he doesn't have enough privileges or hide his name from list of project contacts
- use
<html-version>/<cache-key>
as fragment cache key, where<html-version>
is incremented manually after every change in HTML/CSS of the fragment and<cache-key>
is[class]/[id]-[timestamp]
e.g. "projects/15-20110218104500" - more @ http://37signals.com/svn/posts/3112-how-basecamp-next-got-to-be-so-damn-fast-without-using-much-client-side-ui and http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works
- Caching user's home page (same URL for all visitors, but different content)
- can't cache response in gateway proxy
- can cache response in browser (using validation headers - last-modified/etag)
- use fragment caching (to minimize time/resources spent generating the page if just small part of it changes)
- Caching pages for authenticated users (e.g.
/project/14
)
If the no-cache directive does not specify a field-name, then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server.
- Use
Cache-control: public, no-cache
for authorized users -public
allows gateway cache to cache it,no-cache
forces it to revalidate response with the server - Use
Cache-control: no-cache
and return 401 or 404 for unuathorized users. This way if they become authorized, they will always get the new version
- HTML5 pushState (e.g. PJAX)
Allows to send CSS/JS/HTML layout only on the first request and on the next ones send only HTML. Even with proper asset caching it still saves time on loading and rendering HTML layout and parsing/evaluating JS/CSS files.
- Infinite scrolling pages
Similar to the previous one - allows to send less data to user.
- Single page apps
TL;DR
- Check if it's possible/good idea to use action caching for unauthenticated users to cache 401/404/generic home page/etc
Cache-Control: must-revalidate; max-age=604800