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

Use loading=lazy on images #9

Open
simonw opened this issue Aug 11, 2022 · 3 comments
Open

Use loading=lazy on images #9

simonw opened this issue Aug 11, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Aug 11, 2022

https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading

This could help avoid loading a hundred images on a page with a table that doesn't ever get scrolled.

@simonw simonw added the enhancement New feature or request label Aug 11, 2022
@simonw
Copy link
Owner Author

simonw commented Aug 11, 2022

Had this idea while looking at https://til.simonwillison.net/tils/til and thinking about maybe adding this plugin to that.

@simonw
Copy link
Owner Author

simonw commented Aug 11, 2022

This idea doesn't actually make sense given the way this plugin works at the moment - it embeds base64 images directly into the page, which results in a BIG increase in the size of the output HTML and no opportunities for lazy loading:

return Markup(
'<img src="data:image/{};base64,{}" alt="">'.format(
image_type, base64.b64encode(value).decode("utf8")
)
)

@simonw
Copy link
Owner Author

simonw commented Aug 11, 2022

In order to add lazy loading I'd need to change how the images are served, switching to having them link to a new endpoint (or output renderer) which returns the image read from the database table.

I'd need to think carefully about the security of doing this, since serving content from potentially untrusted sources could result in XSS or similar if not done with care.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant