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

Hook into ajax and limit max concurrency for performance #92

Open
axetroy opened this issue May 15, 2017 · 5 comments
Open

Hook into ajax and limit max concurrency for performance #92

axetroy opened this issue May 15, 2017 · 5 comments

Comments

@axetroy
Copy link

axetroy commented May 15, 2017

In some condition. I need send many many XMLHttpRequst(for example: stat github data in client side)

may be 100 or more request. it's ok in PC browser. but got bad performance in mobile browser.

so, I think, whether there is a lib, to hook into XMLHttpRequst, limit max concurrency.

For example:

Web component loaded and send 100+ http request in 3s.
The good way is splice the request, send 10 request with 10 times.

Not just simple like this: [[1,2,3...10],[1,2,3...10],...[1,2,3...10]]

Like a queue list, if previous request done. then put next request in to the queue
But make sure the max request number always equal 10

API

I think API should look like this:

XMLHttpRequest.setMax(10)

Is there have exist a lib implement this? or who can help?

@axetroy axetroy changed the title Hook into ajax, limit max concurrent for performance. Hook into ajax, limit max concurrency for performance. May 15, 2017
@RangerMauve
Copy link

You should also consider using GraphQL so that you can get a bunch of data in one request

@axetroy
Copy link
Author

axetroy commented May 15, 2017

@RangerMauve
Thanks for told me that. Actually, I wanna build a web app without server.
All data comes from 3th party API. like github api v3.

@RangerMauve
Copy link

@axetroy Yeah, github actually supports GraphQL already so you could look into that to see if you can restructure your app to be more efficient with requests

@axetroy
Copy link
Author

axetroy commented May 15, 2017

@RangerMauve
That's so cool! resolved it, thanks.

But I still really hope there is a solutionin in client side.

@sindresorhus
Copy link
Owner

Use window.fetch with p-map. Polyfill for fetch here.

const pMap = require('p-map');

const sites = [
	'ava.li',
	'sindresorhus.com',
	'github.com',
	...
];

const mapper = url => fetch(url).then(response => response.json());

pMap(sites, mapper, {concurrency: 10}).then(result => {
	console.log(result);
});

@sindresorhus sindresorhus changed the title Hook into ajax, limit max concurrency for performance. Hook into ajax and limit max concurrency for performance May 15, 2017
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

3 participants