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

Duplicate and concurrent requests fired when scroll very fast #148

Open
Shanison opened this issue Jan 24, 2018 · 0 comments
Open

Duplicate and concurrent requests fired when scroll very fast #148

Shanison opened this issue Jan 24, 2018 · 0 comments
Assignees
Labels

Comments

@Shanison
Copy link

Hi,

We are using jscroll to load ajax contents. After loading the first page, if you try to keep scrolling down very very fast. It will shows two loading html and then fire a lot of ajax requests to load subsequent pages.

In the library, there is an _observe function which is triggered whenever we scroll down. It has a way to prevent loading of next page until the previous request has been finished by leveraging the data.waiting value. When there is a previous request being sent to the server, this data.waiting is set to true and it is set to false after the data is returned.

                if (!data.waiting && iTotalHeight + _options.padding >= $inner.outerHeight()) {
                    //data.nextHref = $.trim(data.nextHref + ' ' + _options.contentSelector);
                    _debug('info', 'jScroll:', $inner.outerHeight() - iTotalHeight, 'from bottom. Loading next request...');
                    return _load();
                }

However, if you look at below code.

                        data.waiting = false;
                        data.nextHref = $next.attr('href') ? $.trim($next.attr('href') + ' ' + _options.contentSelector) : false;
                        $('.jscroll-next-parent', $e).remove(); // Remove the previous next link now that we have a new one
                        _checkNextHref();
                        if (_options.callback) {
                            _options.callback.call(this);
                        }

It looks like the data.waiting is set to false to early. Once it is set to false, the _observe will run and try to load the next page with previous link instead of the new next link. This only happens when we scroll very fast.

Should we set data.waiting = false to execute until the whole processing is done to prevent this issue?

                        data.nextHref = $next.attr('href') ? $.trim($next.attr('href') + ' ' + _options.contentSelector) : false;
                        $('.jscroll-next-parent', $e).remove(); // Remove the previous next link now that we have a new one
                        _checkNextHref();
                        if (_options.callback) {
                            _options.callback.call(this);
                        }
                        data.waiting = false;
@Shanison Shanison changed the title Load duplicate requests when scroll very fast Duplicate and concurrent requests fired when scroll very fast Jan 24, 2018
@pklauzinski pklauzinski self-assigned this Feb 7, 2018
@pklauzinski pklauzinski added the bug label Feb 7, 2018
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