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

Warning about bad formats order or maybe some reordering of outputs object? #71

Open
zachleat opened this issue Feb 14, 2021 · 5 comments
Labels

Comments

@zachleat
Copy link
Member

If you use formats: ["jpeg", "webp", "avif"] the generateHTML utility will generate markup with <source> in the wrong order.

There is some intentional behavior there that we wouldn’t want to destroy, maybe you’d want "jpeg", "png" or "png", "webp". At this point in time "avif" should never be last though. And it’s very unlikely "webp" would come after "jpeg" or "png". I doubt you’d want "webp" before "avif" too.

So, not sure. I think warnings are in order so that we can lean towards teaching instead of using automation to protect from requiring the knowledge.

@zachleat zachleat added the enhancement New feature or request label Feb 14, 2021
@zachleat
Copy link
Member Author

zachleat commented Feb 23, 2022

Here’s a rule list I think would be useful:

  • avif should always be before jpeg, webp, and png.
  • webp should always be before jpeg and png
  • png should be preferred to jpeg when the image has transparency separate issue on Handle images with an alpha channel #105
  • svg should always be first for super complex large SVG we may want to use raster instead

Are there others?

@AleksandrHovhannisyan
Copy link
Contributor

Hey, hope it's cool to chime in. My only concern with a warning would be that it might get lost in the output/people might not notice it easily. Is throwing an error too heavy-handed? Might make sense to auto-sort the formats to prioritize webp/avif as a best practice.

@zachleat
Copy link
Member Author

Ah @AleksandrHovhannisyan I do think we should auto-sort for those small set of rules (paired with an opt-out) but also show a warning that a re-sort happened?

@AleksandrHovhannisyan
Copy link
Contributor

Yup, that makes sense!

@AleksandrHovhannisyan
Copy link
Contributor

AleksandrHovhannisyan commented Feb 24, 2022

@zachleat Are you accepting PRs for this enhancement? I'd be happy to contribute one if you think the scope is manageable, and unless you'd prefer to tackle it yourself.

Haven't dived back into the code yet, but I'm thinking it should be simple. We can have a map from extensions to numeric priorities and then use it to sort the formats array. Is there already a standard way of communicating warnings in the plugin?

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

No branches or pull requests

2 participants