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

Use visibility to show/hide next slides to allow preloading to actually work #2913

Merged
merged 3 commits into from Apr 19, 2016

Conversation

mkhatib
Copy link
Contributor

@mkhatib mkhatib commented Apr 14, 2016

Fixes #2742

@mkhatib
Copy link
Contributor Author

mkhatib commented Apr 14, 2016

cc/ @dvoytenko

@camelburrito
Copy link
Contributor

update the tests?

@mkhatib
Copy link
Contributor Author

mkhatib commented Apr 14, 2016

I couldn't find any tests that actually test for preloads or visibility, I can add some test cases though

@camelburrito
Copy link
Contributor

camelburrito commented Apr 14, 2016

yes please! ping me once you have added the tests.

@mkhatib
Copy link
Contributor Author

mkhatib commented Apr 18, 2016

@sriramkrish85 added test cases PTAL

@camelburrito
Copy link
Contributor

@cramforce - do you wanna take a final pass?

it('should preload slides in direction of navigation', () => {
expect(slide0.style.visibility).to.be.equal('visible');
expect(slide1.style.visibility).to.be.equal('hidden');
expect(slides.scheduleLayout.calledWith(slide0));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think these are not running properly. These need to .to.be.true appended, will update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed should now actually run these.

@@ -49,7 +49,7 @@ export class AmpSlides extends BaseCarousel {
this.slides_.forEach((slide, i) => {
this.setAsOwner(slide);
// Only the first element is initially visible.
slide.style.display = i > 0 ? 'none' : 'block';
Copy link
Member

Choose a reason for hiding this comment

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

I just need some context here: display: none is much better from a performance pov. But if we do want to render them, then this change is good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah the problem with display: none is that resources will totally ignore the element and won't schedule preload for it although the carousel is asking the resources to schedule preload for them. Some more context on #2742

If we expect a big hit on performance maybe a compromise is to use both visibility and display. Where visibility would be used for for +1/-1 window length (e.g. for slider this is 1 slide before and 1 slide after) and display:none the rest outside that window. This would complicate the logic slightly but if we expect the performance to be worth it maybe it's worth getting it right.

In anyway, since we might be working on big changes for carousel maybe we can keep that in mind in the new design.

Copy link
Member

Choose a reason for hiding this comment

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

+1 Make sure to comment that there when we are reviewing the design.

@mkhatib mkhatib merged commit 5eb818d into ampproject:master Apr 19, 2016
@mkhatib mkhatib deleted the actually-preload-slides branch April 19, 2016 21:54
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

Successfully merging this pull request may close these issues.

None yet

3 participants