Skip to content

Conversation

@ebinnion
Copy link
Contributor

@ebinnion ebinnion commented Nov 2, 2017

Will help speed by minimizing the number of images we download when the page is first viewed.

This plugin is largely based on the Lazy Load plugin, but has been updated to make use of IntersectionObserver. IntersectionObserver does not have great browser support. But, we are using a polyfill that will add the necessary functionality.

I have several questions, which are listed in this comment, mostly around attribution and how we should load the polyfill.

Besides that, this PR should be ready for some review and testing.

To test:

  • Checkout PR
  • Load admin page
  • Go to $site.com/wp-admin/admin.php?page=jetpack_modules and enable the Lazy Images module
  • Go to front-end of site, and ensure that images get loaded as you scroll down the page. Tip: you can filter the network panel to only show img requests
  • Ensure that there are no JS errors
  • Test various browsers

@ebinnion ebinnion added this to the 5.6 milestone Nov 2, 2017
@ebinnion ebinnion self-assigned this Nov 2, 2017
@ebinnion ebinnion requested a review from a team as a code owner November 2, 2017 14:02
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer a TODO

@ebinnion ebinnion force-pushed the add/lazy-images branch 6 times, most recently from 0d74c6e to 3982c84 Compare November 3, 2017 18:26
@ebinnion
Copy link
Contributor Author

ebinnion commented Nov 3, 2017

At this point, things are functional in IE11 and Edge as well as Chrome.

Todos:

  • Add attribution to VIP team, @mjangda, and others
  • Integrate with infinite scroll. Currently, the script only fire once. We also need to fire each time posts are added to the dom.
  • Add conflicting plugins

@ebinnion
Copy link
Contributor Author

ebinnion commented Nov 3, 2017

@mjangda mentioned that we should consider pulling updates from here:

Automattic/lazy-load#10

@ebinnion
Copy link
Contributor Author

ebinnion commented Nov 6, 2017

At this point, we are functional back to IE9 as well as other browsers.

Known issues/questions at this point are:

  • How to properly attribute the IntersectionObserver polyfill and other code?
  • Is it OK to load the polyfill directly in lazy-images.js, or do we need to drop that in it's own file?
  • If we keep it in the same file, is it OK to leave it minified, or could that break the build process if we minify again when we eventually start minifying all module JS?
  • The Lazy Load repo above includes unit tests. We should probably port those over and perhaps add some more.

Note: I tried very hard to not have jQuery as a dependency here. But, since the post-load event is fired via jQuery, and jQuery uses a custom event system, it seems like we currently require jQuery, at a minimum to support Infinite Scroll.

@ebinnion ebinnion added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 6, 2017
@@ -0,0 +1,134 @@
/* globals IntersectionObserver, jQuery */

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the license for the polyfill need to go here? Also, I'd like to keep the polyfill in this same file to minimize network requests. It bails early if it detects IntersectionObserver is in window, so it shouldn't cause issues. If we leave it here though, should me unminify it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just include the polyfill licence in Jetpack license, or somewhere like that. I don't think we need to serve it to the browser.

* @param string The URL to the placeholder image
*/
return apply_filters(
'lazyload_images_placeholder_image',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to use the same filters as the Lazy Load plugin to allow for easy updating for VIP and other users. Should we use something else though?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am torn. I guess we should keep them the same though. Sites switching from the existing plugin will experience brokenness/regressions otherwise, and people switching from other plugins won't care. Developers might think it's weird that we didn't prefix it with jetpack_, but only for about 5 seconds.

Copy link
Member

Choose a reason for hiding this comment

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

It would be good to leave a comment why we choose not to prefix it with jetpack_

@gravityrail
Copy link
Contributor

could that break the build process if we minify again when we eventually start minifying all module JS

Minifying twice shouldn't break things. However, let's put this in un-minified so that people can read the code, and so that the unminified version can include its own license.

The Lazy Load repo above includes unit tests. We should probably port those over and perhaps add some more.

We can add them later if we want. I don't want to have this as a super-long-lived PR, and I think if we're confident this works it would be good to get it merged so we can get it in people's hands ASAP.

@gravityrail
Copy link
Contributor

Is there any way to only load the intersection observer if it's necessary?

Copy link
Contributor

@gravityrail gravityrail left a comment

Choose a reason for hiding this comment

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

This is awesome

@gravityrail gravityrail added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Nov 6, 2017
@ebinnion ebinnion added [Status] In Progress and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Nov 6, 2017
@ebinnion
Copy link
Contributor Author

ebinnion commented Nov 6, 2017

In talking to @oskosk, we realized that the Apache 2.0 license on the current IntersectionObserver polyfill is not compatible with GPLv2. So, I'll need to fix that before we can merge.

@gravityrail's did a search and found an MIT-licenses IntersectionObserver that I'll test tomorrow: https://github.com/que-etc/intersection-observer-polyfill

@ebinnion
Copy link
Contributor Author

ebinnion commented Nov 7, 2017

I've now updated the IntersectionObserver polyfill to use the above-linked MIT project. This can now be reviewed again.

Copy link
Contributor

@oskosk oskosk left a comment

Choose a reason for hiding this comment

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

LGTM. Tested well even in combination with the mentioned plugin. The issue when photon is active, remains, but it's a matter for another PR

@oskosk oskosk merged commit 6b47600 into master Nov 10, 2017
@oskosk oskosk deleted the add/lazy-images branch November 10, 2017 20:47
jeherve added a commit that referenced this pull request Nov 24, 2017
oskosk pushed a commit that referenced this pull request Nov 28, 2017
* Changelog 5.6: create base for changelog.

* Update changelog with 5.5.1 info.

* Changelog: add #7930 and #8238

* Changelog: add #8076

* Changelog: add #8100

* Changelog: add #8117

* Changelog: add #8141

* Changelog: add #8143

* Changelog: add #8147

* Changelog: add #8149

* Changelog: add #8153

* Changelog: add #8173

* Changelog: add #8184

* Changelog: add #8196

* Changelog: add #8199

* Changelog: add #8093

* Changelog: add #8171

* Changelog: add #8182

* Changelog: add #8202, #8222

* Changelog: add #8228

* Changelog: add #8240

* Changelog: add #8251

* remove AL card change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants