Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #featured-bg-{{id}} not resizing Unsplash images #549

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

paulo-pertierra
Copy link
Contributor

@paulo-pertierra paulo-pertierra commented Sep 27, 2024

Problem:

Unsplash images are not resizing properly because the CSS property background-image being added to #featured-bg-{{id}} is HTML-encoded.

You can try this yourself by adding an Unsplash image in the Unsplash button beside the Add feature image
image

Then look at your request in the browser using liebling theme to see the HTML-encoded query, then use the Casper theme to see the proper query.

The HTML-encoded query string added to Unsplash URLs shows up as:

crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wxMTc3M3wwfDF8c2VhcmNofDEwfHxhJTIwbWFuJTIwcmlkaW5nJTIwYSUyMGJpa2UlMjBkb3duJTIwYSUyMHN0cmVldCUyMG5leHQlMjB0byUyMHRhbGwlMjBidWlsZGluZ3xlbnwwfHx8fDE3MjczOTU5MDJ8MA&ixlib=rb-4.0.3&q=80&w=600

Solution:

Add a triple bracket handlebar to properly parse the text instead:

crop=entropy&cs=tinysrgb&fit=max&fm=webp&ixid=M3wxMTc3M3wwfDF8c2VhcmNofDEwfHxhJTIwbWFuJTIwcmlkaW5nJTIwYSUyMGJpa2UlMjBkb3duJTIwYSUyMHN0cmVldCUyMG5leHQlMjB0byUyMHRhbGwlMjBidWlsZGluZ3xlbnwwfHx8fDE3MjczOTU5MDJ8MA&ixlib=rb-4.0.3&q=80&w=320

Result:

10.4MB Request size
image

versus

956KB Request size
image

This might save homepage first load dozens of MBs of data and shaves much time when the blog uses Unsplash.

@eddiesigner
Copy link
Owner

Good catch, thank you!

@eddiesigner eddiesigner merged commit 5aaee33 into eddiesigner:master Sep 27, 2024
@paulo-pertierra
Copy link
Contributor Author

Thanks for the beautiful theme btw! 🙌

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