Skip to content

perf: speed up hero background load on home page#230

Open
mmcky wants to merge 2 commits into
mainfrom
perf/hero-background-load
Open

perf: speed up hero background load on home page#230
mmcky wants to merge 2 commits into
mainfrom
perf/hero-background-load

Conversation

@mmcky

@mmcky mmcky commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

Loading quantecon.org shows a noticeable delay before the hero background image appears.

The hero background is set as a CSS background-image (main.scss#L484). Because the URL is buried in CSS, the browser's preload scanner can't find it during HTML parse — the image fetch only begins after main.css has downloaded and been parsed (behind the render-blocking Bootstrap CDN stylesheets). On top of that, mountains1.jpg was 532 KB at 2400×1595, larger than any viewport needs.

Changes

1. Preload the hero image (gated to the home layout, since that's the only page with the hero). This lets the browser start fetching the image during the initial HTML parse, in parallel with the CSS, instead of after the CSS round-trip.

2. Optimize the image. Resized 2400×1595 → 1920×1276 and re-encoded as a progressive JPEG at quality 82: 532 KB → 236 KB (~55% smaller). The hero renders a rgba(0,0,0,0.55) dark overlay on top of the photo, so the quality change is imperceptible.

Together these mean the background starts downloading earlier and finishes sooner.

Verification

  • bundle exec jekyll build succeeds.
  • Confirmed the <link rel="preload" as="image"> tag renders on _site/index.html and is absent from internal pages.

Possible follow-ups (not in this PR)

  • Serve WebP/AVIF via image-set() for a further size cut.
  • Promote the background to a real <img> with fetchpriority="high" so the preload scanner sees it in markup.

🤖 Generated with Claude Code

The home page hero uses a CSS `background-image`, so the browser can't
discover the image URL until main.css has downloaded and parsed — the
fetch only starts after the CSS round-trip, delaying when the background
appears.

Two changes:

- Preload the hero image in <head> (gated to the home layout) so it
  starts downloading during initial HTML parse, in parallel with CSS
  rather than after it.
- Optimize mountains1.jpg: resize 2400x1595 -> 1920x1276 and re-encode
  as progressive JPEG at q82, 532KB -> 236KB (~55% smaller). The hero's
  dark 55% overlay makes the quality change imperceptible.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 3, 2026 21:46
@netlify

netlify Bot commented Jul 3, 2026

Copy link
Copy Markdown

Deploy Preview for grand-swan-ca5201 ready!

Name Link
🔨 Latest commit b8c2a71
🔍 Latest deploy log https://app.netlify.com/projects/grand-swan-ca5201/deploys/6a482defddbca600085424ff
😎 Deploy Preview https://deploy-preview-230--grand-swan-ca5201.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves perceived performance on the QuantEcon home page by starting the hero background image download during initial HTML parsing (instead of waiting for CSS to download and parse).

Changes:

  • Adds a home-page-only <link rel="preload" as="image"> for the hero background asset (/assets/img/mountains1.jpg) in the default layout.

@mmcky

mmcky commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

@DrDrij do you have time to cast an eye over this PR? Just trying to improve load time for the background image -- the preview is working nicely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants