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

fetch is now available as a polyfill or a self-contained library #192

Closed
wants to merge 1 commit into from
Closed

fetch is now available as a polyfill or a self-contained library #192

wants to merge 1 commit into from

Conversation

steveluscher
Copy link
Contributor

This refactor permits usage of whatwg-fetch as:

  • a polyfill that modifies self

    require('whatwg-fetch');

  • or as a self-contained module that doesn't

    var fetch = require('whatwg-fetch/library');

Should you use the second form in a project whose code is sometimes executed on the server and sometimes on the client (as is the case with certain classes of apps that do server rendering, or are tested in headless environments), this has the nice side effect of not throwing an exception on import just because self is undefined.

This is similar to the approach taken by core-js.

@mislav
Copy link
Contributor

mislav commented Aug 12, 2015

Sorry, we're not fans. #184 (comment) #31 (comment)

If we accept this pull request, we can't use fetch on GitHub.com anymore, where we don't use any JS module loader. It would be pretty hard to convince us to make a change that prevents us from using our own library in our own product.

@mislav mislav closed this Aug 12, 2015
@steveluscher
Copy link
Contributor Author

Thanks for taking a look!

I think you could continue to use it on GitHub, though. This PR builds a ./fetch.js that works just like your old one – with no module loader needed. It's only the additional (and optional) ./library/index.js version that follows the CommonJS pattern.

@mislav
Copy link
Contributor

mislav commented Aug 12, 2015

This PR builds a ./fetch.js that works just like your old one – with no module loader needed.

The creation of ./fetch.js seems to require an extra build step with webpack. That adds complexity to our assets setup. Right now we simply fetch each JS library we use with Bower and load it directly into the site, no post-processing or intermediate build steps needed.

Your "compiled" version of fetch.js is also 0.5 kB larger than ours after minification. Not a huge deal, but considering that the whole library is just over 5k, a 10% size increase is one more reason against our adoption of that approach.

Thanks for taking the time to break down our polyfill into modules, though. It's a good example of how it could be done if a library wanted to take that approach. We feel that our polyfill is still simple enough that it can stay in a single file.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants