The real challenge: making the entire web fast
wimleers.com/article/performance-calendar-2013-making-the-entire-web-fast
Silos are fast, the long tail is slow.
Let's fix that.
Why do this: a quick reminder.
The edge?
assets ⟷ HTML
Why?
Because closer to the end user (less latency).
This talk is about using a CDN to cache the HTML.
max-age = 300
… but stale content!
Purge affected URLs
… but brittle!
Separate domain ⟷ passthrough
Nothing is cached!
Better architecture.
No more hacks.
invalidation | ➞ | cache tags |
authenticated users | ➞ | cache contexts |
cache tags | ≈ | data dependencies |
cache contexts | ≈ | request context dependencies |
cache tags | ➞ | invalidate tag X |
cache contexts | ➞ | know what to Vary by |
if it varies too much, placeholder it |
On a Response
:
X-Drupal-Cache-Tags
headerX-Drupal-Cache-Contexts
header↪ cache tags
Today.
Simple.
Cached worldwide!
Acquia Cloud Edge
or
CloudFlare Enterprise
Near future…
Trivial.
Affordable for all: cached locally in Varnish
Affordable for many: cached worldwide (CDN)
Invalidation solved: benefits everyone!
And now… something even cooler!
Because one fateful day …
... a shopping cart was added to the site.
And then it looked like this:
And the webserver ran away screaming in terror and was never to be found again.
You don't believe me?
Let's test that …
Site is fast (180 ms), but the user experience is poor.
So let's make the pages less dynamic
But the Web 3.0 is all about personalized experiences!
I need dynamic pages!
Or I am back to using plain HTML!
And don't forget about my shopping cart!
Fortunately!
Drupal 8 has a solution for that!
… and it is already in core!
esi-8.x-1.x
(fork; not yet released)<esi:include src="/esi-fragment/esi_6c9a85d4002185c82" />
↪ cache tags + cache contexts
Works for anonymous users out of the box.
Needed for authenticated user caching.
Standardized solution for a complex problem.
Out of Within reach for 99%.
Unmatched.
Some hosting providers will step up.
So, Drupal 8 can be super fast!
It can be cached at the edge.
Without the pain of other CMSes (including Drupal 7).
It just requires all of us to think of a few things while developing custom modules or contributed modules.
The theory of how we make Drupal fast.
drupal_add_css()
, drupal_add_js()
…
#attached
asset libraries solve thaturl()
's output depended on:
<front>
configuration
+
Cacheability bubbled during rendering!
Try to make this thought process a habit:
I'm rendering something. That means I must think of cacheability!
Is this something that's expensive to render, and therefore is worth caching?
↪︎ If "yes": cache keys.
$build['#cache']['keys'] = ['node', 5, 'teaser'];
Does the representation of the thing I'm rendering vary per combination of permissions, per URL, per interface language, per … something?
↪︎ If "yes": cache contexts.
$build['#cache']['contexts'][] = 'user.permissions';
$build['#cache']['contexts'][] = 'url';
~ HTTP's Vary
header
What causes the representation of the thing I'm rendering become outdated?
↪︎ If "yes": cache tags.
$build['#cache']['tags'][] = 'node:5';
$build['#cache']['tags'][] = 'user:3';
$build['#cache']['tags'][] = 'taxonomy_term:23';
When does the representation of the thing I'm rendering become outdated?
↪︎ If "yes": cache max-age.
$build['#cache']['max-age'] = Cache::PERMANENT;
~ HTTP's Cache-Control: max-age
header
All relevant objects provide cacheability metadata!
interface CacheableDependencyInterface {
public function getCacheContexts();
public function getCacheTags();
public function getCacheMaxAge();
}
Implemented by:
Come see our other session tomorrow!
A client-side reverse proxy!
Logic defined in JavaScript!
Zero latency!
…allowed Fabian & I to focus on this!
wimleers.com/talk/caching-at-the-edge-cdns-for-everyone