Commit 08a8ebd
perf: self-host anchor-js and add intrinsic dimensions to hero overlay image (Core Web Vitals) (#20725)
* perf: self-host anchor-js and add intrinsic dimensions to hero overlay image
Two low-risk Core Web Vitals fixes surfaced while researching LCP/INP/CLS
for pulumi.com against the web.dev vitals definitions:
- Vendor anchor-js 4.1.0 (static/js/anchor-js.min.js) instead of loading it
from cdnjs on every docs/tutorials/blog/authors/tags/registry page. The
vendored copy is byte-identical to the cdnjs/jsdelivr release (verified
against cdnjs's own published sha512 SRI hash). This removes a third-party
DNS/TLS/connection dependency and single point of failure from every
content page; it was already async+defer so this is not an LCP-blocking
fix, but it does harden availability and drops one origin from the
connection waterfall.
- Add explicit width/height to the two call sites of the home/product-page
hero overlay SVG in template-hero.html (split and centered layouts), which
is frequently the LCP element. This follows the exact pattern of the
already-merged PR #20561 (footer background SVG), whose partial
(fingerprinted-img.html) already supports width/height -- the hero overlay
call sites just weren't passing them. Eliminates a CLS source on the
highest-traffic page on the site (home page: 26,424 views / 28 days,
94.9% desktop per GA4).
* fix: derive hero overlay dimensions from code_aspect_ratio instead of SVG resource.Width
resources.Get on an SVG returns a generic (non-image) resource with no
.Width/.Height, so calling $overlayImgRes.Width/.Height on the hero
code-overlay SVG broke template execution on the homepage and the
/product/infrastructure-as-code/ page -- exactly the pages the CLS fix
targeted.
Derive the intrinsic width/height instead from the page's existing
code_aspect_ratio frontmatter (e.g. "666/513"), which already drives
the container's CSS aspect-ratio, so both stay in sync. Falls back to
omitting width/height when the frontmatter value is absent or malformed.
Fixed at both hero layout call sites (split and centered variants).
Also rewrote the anchor-js vendoring comment in head.html to cite a
verifiable fact (the vendored file's SHA-512 matches cdnjs's own
published SRI hash for anchor-js@4.1.0/anchor.min.js) instead of an
unfalsifiable "byte-identical" claim.
Verified with a full `make build`: the homepage and
/product/infrastructure-as-code/ now render the overlay img tag with
correct width/height attributes and no template errors.
---------
Co-authored-by: workprentice <257153108+workprentice@users.noreply.github.com>1 parent b16c29f commit 08a8ebd
3 files changed
Lines changed: 39 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
510 | | - | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
511 | 518 | | |
512 | | - | |
| 519 | + | |
513 | 520 | | |
514 | 521 | | |
515 | 522 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
175 | 186 | | |
176 | 187 | | |
177 | 188 | | |
| |||
245 | 256 | | |
246 | 257 | | |
247 | 258 | | |
248 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
249 | 271 | | |
250 | 272 | | |
251 | 273 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments