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

question: feature logic #58

Open
dargmuesli opened this issue Aug 10, 2023 · 4 comments
Open

question: feature logic #58

dargmuesli opened this issue Aug 10, 2023 · 4 comments

Comments

@dargmuesli
Copy link
Contributor

dargmuesli commented Aug 10, 2023

I'm wondering how the feature logic is intended to work:

const features = await polyfillist(options.target)

As I understand it, the code currently retrieves all features that are not implemented in browsers which are marked as supported using browserslist and limits the polyfills returned to the matching features.

Now, if that's right, why would you do that?
Isn't the feature list meant to list only the features actually required by website's source, not every feature unsupported by supported browsers?

Example:

Let's say I wanted to support "firefox 116". npx polyfillist "firefox 116" returns:

HTMLInputElement.prototype.valueAsDate
es2023
setImmediate

Now, a browser that uses none of those features would request https://polyfill.io/v3/polyfill.min.js?features=HTMLInputElement.prototype.valueAsDate%2Ces2023%2CsetImmediate which results in 5kb (transferred 3kb).

Wouldn't it be better to expose features as a module option (detecting required features is surely a harder task to solve for now) so that module users can specify which features they use / polyfills they require?

@adenvt
Copy link
Owner

adenvt commented Aug 11, 2023

@dargmuesli Yes, as you mention, this library actually for lazy people (like me 😆) who don't know what features i should to include.

If you know what features should be include, i recommended to use original library from polyfill.io.

@dargmuesli
Copy link
Contributor Author

Ok, so that logic is meant to load every polyfill for the browsers supported, thus limiting the features to the ones required for supported browsers only, but not to the features actually used. So older browsers are by that definition not meant to be supported at all, which could still be possible if required features were specified instead. Right?

Then would you think we could add that to the README?
And also: what do you think about adding the possibility to specify features (potentially disabling the "everything supported browsers" logic) as module options? Vs. directly using polyfill.io's api, that is.

@adenvt
Copy link
Owner

adenvt commented Aug 14, 2023

@dargmuesli Almost correct, FYI, polyfill.io is service which load polyfill based on User-Agent. But when we want to use polyfill.io, we need to use some kind a preset which feature should be enable.

That way i created polyfillist. it take all features from polyfill.io, check the feature requirement, and return the feature name which possible required in current browserslist config.

But cons of it is some features might be not used in project at all.
And feature which no browser has implemented (like setImmediately) will always included (older and newer browser).

I agree with manual features defined. But for now, i have no plan how to do it. Because it's an array, and config with array always come with 3 possible cases:

  • I want to add some item with it (default value + some items)
  • I want to remove some of it (default value - some items)
  • I want to completely change of it (replace default value)

@dargmuesli
Copy link
Contributor Author

Ok! I'd propose to keep the current behavior if no custom features property is given and use exactly what's given in the features property if set. Reason being that if someone sets their features they know exactly which ones they require, thus not needing to include all possibly required polyfills for the supported browsers.

That would also enable projects specifying required features to potentially support browsers even older than the ones defined as supported in the browserslist definition, I imagine.

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

No branches or pull requests

2 participants