Conference talk presented at PHP South Coast 2017. Ten concrete ways to improve web performance, split between quick tactical wins and longer-term overarching strategies.
2. The web is no longer simply a
platform for serving static
documents.
3. Today we can build rich, highly
interactive applications on the
web.
4.
5. And while users expect rich
interactivity, they also expect
performance.
6.
7. Measure performance Reuse data
Load important resources first
Manage perceived
performance
Run less code Anticipate poor connections
Parallelize requests
Don’t try to do everything at
once
Only ask for what you need Send content as it’s ready
11. Synthetic performance metrics
● Measure performance in isolation
○ Tools: webpagetest, lighthouse
○ Use real devices if possible
○ Emulate network connections
13. Common client testing mismatches
● Browser types and versions
● Device CPU power
● Network conditions
○ Bandwidth
○ Latency
○ Intermittent connections
14. Real User Metrics (RUM)
● CDNs and other services can collect
aggregate user performance data
● Data is less detailed, but more accurate
○ But influenced by outside factors.
● Problems will often manifest in the upper
90th percentile rather than the mean
15.
16.
17.
18.
19.
20.
21. Prioritize resources the user is likely
to need first (e.g., above the fold
images) before those they won’t
need until later.
26. is the core of the problem we
have to solve [...] legitimately difficult problems.
is all the stuff that doesn’t
necessarily relate directly to the solution, but that we
have to deal with anyway.
Neal Ford, Investigating Architecture and Design (2009)
27. We can have essential and
accidental performance costs,
too.
* And often it can be hard to tell the difference.
38. Distribute resource requests across multiple domains, allowing
the browser to parallelize requests
… but there’s overhead. New DNS lookup, time to establish
connection.
39. Distribute resource requests across multiple domains, allowing
the browser to parallelize requests
… but there’s overhead. New DNS lookup, time to establish
connection.
General guideline: shard across two domains.
42. H2 can download multiple files in
parallel over a single multiplexed
connection.
43.
44. H2 can download multiple files in
parallel over a single multiplexed
connection.
45. Adopt H2 today
● Ensure resources are served via HTTPS
● If you use a content-delivery network (CDN)
there’s a good chance it supports HTTP/2 today.
● If you’re already domain sharding, make sure
those hostnames resolve to the same IP.
54. GraphQL can help prevent
over-serving data, and reduce the
number of overall requests.
55.
56.
57.
58.
59. How can you avoid re-requesting
data we’ve already downloaded?
60.
61.
62. ● Caching layers on the server
● Single-page application on the client, share data between
routes or components
○ Normalized top-level data
○ Smart client-side caching
71. “Progressive Web Apps”
● PWAs focus on building web applications that work well in
environments with slow, intermittent, or zero network
connectivity.
● More than just “offline” support, PWA techniques can provide
features of your app even when the network connection is
imperfect.
72. ServiceWorker
● ServiceWorker is browser technology that allows a separate
script to run in the browser background, separate from your
web site, intercept and handle network requests, and
communicate back to your web application.
● You can cache data and other page assets in order to serve
them to your web application even if no external network
connection is available.
73.
74. The browser has a lot to do on a
single thread when rendering a
page...don’t let JavaScript get in the
way.
81. Why make the user wait for the
whole page to be done?
82. “The general idea is to decompose web pages into small
chunks called pagelets, and pipeline them through
several execution stages inside web servers and
browsers.”
Changhao Jiang, “BigPipe: Pipelining web pages for high performance” (2010)
83.
84. ● Streaming HTML
○ HTML Chunked Encoding
○ ob_flush()
● Client-side powered
○ XHR requests for individual components
87. Measure performance Reuse data
Load important resources first
Manage perceived
performance
Run less code Anticipate poor connections
Parallelize requests
Don’t try to do everything at
once
Only ask for what you need Send content as it’s ready