sxg-rs
sxg-rs is a set of tools for generating signed exchanges at serve time:
cloudflare_worker
runs on Cloudflare Workers.fastly_compute
runs on Fastly Compute@Edge.sxg_rs
is the Rust library that drives both, and could be used as a basis for other serverless platforms.
The tools here are designed to enable sites to be prefetched from Google Search in order to improve their Largest Contentful Paint, one of the Core Web Vitals.
Verify and monitor
This code was released in July 2021 and thus hasn't yet had a lot of real-world testing. After installing, please verify and monitor the results.
Preview in Chrome
To preview the results in the browser:
- In development, set Chrome flags to allow the certificate.
- Use an extension such as ModHeader to set the
Accept
header totext/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
(equivalent to what Googlebot sends). - Explore the results in the DevTools Network tab.
Ensure compatibility with SXG
The Google SXG Cache may reuse an SXG for several visits to the page, or for several users (until SXG expiration). Follow these instructions to ensure all signed pages are compatible with such reuse. To opt some pages out of signing, set the Cache-Control
header to include private
or no-store
in the upstream server.
Preload subresources
LCP can be further improved by instructing Google Search to prefetch render-critical subresources for the page. To do so, add a Link: rel=preload
header and a matching Link: rel=allowed-alt-sxg
header in the upstream server, as in this example. To compute the header-integrity
for each subresource, run:
$ go install github.com/WICG/webpackage/go/signedexchange/cmd/dump-signedexchange@latest
$ dump-signedexchange -uri $URL -headerIntegrity
To ensure the header-integrity
remains stable, eliminate frequently changing headers from the upstream response such as Date
.