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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 amp-autocomplete: Fetch remote data after first user interaction #24645

Merged
merged 4 commits into from Sep 23, 2019

Conversation

caroqliu
Copy link
Contributor

Resolves #23772

Currently amp-autocomplete will fetch remote data source on layout. This change:

  • delays this initial fetch until the user first interacts with the input field contained in the component
  • does not impact behavior for data provided inline

Copy link

@sparhami sparhami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense as the default behavior, but it might be nice to support prefetching of the data (via an attribute) to improve responsiveness for users.

I would also suggest looking into using touchstart for prefetching of the data (in addition to starting the fetch if you have not already on focus). The focus event does not occur until touchend (or mouseup), which can occur hundreds of milliseconds after touchstart due to the human latencies involved of touching and releasing.

The trade-off is that you start prefetching results when the user might have been scrolling, and happened to swipe on the input during their scroll. Since many auto completes are used as search bars (near the top of the page), users are unlikely to scroll on that part of the screen, so I'm not sure that this is a huge downside.

extensions/amp-autocomplete/0.1/amp-autocomplete.js Outdated Show resolved Hide resolved
extensions/amp-autocomplete/0.1/amp-autocomplete.js Outdated Show resolved Hide resolved
@caroqliu
Copy link
Contributor Author

Thanks for the comments! Filed #24687 as follow up to support prefetching through an attribute. Also added listening on touchstart since it is unlikely for scrolling to occur on this element. cc @sparhami

@caroqliu caroqliu merged commit ba2fb76 into ampproject:master Sep 23, 2019
@caroqliu caroqliu deleted the autocomplete-req branch September 23, 2019 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-autocomplete does request on page load
3 participants