Integration of lazysizes, a lightweight lazy loader, into Plone.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src/collective Code cleanup (#74) Oct 17, 2018
webpack
.codacy.yml
.eslintrc
.gitignore
.travis.yml Avoid issues with Coveralls Oct 17, 2018
CHANGES.rst
CONTRIBUTORS.rst
MANIFEST.in
README.rst
bootstrap.py
buildout.cfg
setup.cfg
setup.py

README.rst

collective.lazysizes

Life, the Universe, and Everything

This package integrates lazysizes, a lightweight lazy loader, into Plone.

lazysizes is a fast, SEO-friendly and self-initializing lazyloader for images (including responsive images picture/srcset), iframes, scripts/widgets and much more. It also prioritizes resources by differentiating between crucial in view and near view elements to make perceived performance even faster.

By using this package you can expect reductions of up to 80% in load time, 75% in page size and 50% in number of requests.

Mostly Harmless

These are some sites using collective.lazysizes:

As long as we have tested, lazysizes seems not to interfere with image indexing made by crawlers like Googlebot.

Got an idea? Found a bug? Let us know by opening a support ticket.

Don't Panic

Installation

To enable this package in a buildout-based installation:

  1. Edit your buildout.cfg and add collective.lazysizes to the list of eggs to install:
[buildout]
...
eggs =
    collective.lazysizes

After updating the configuration you need to run ''bin/buildout'', which will take care of updating your system.

Go to the 'Site Setup' page in a Plone site and click on the 'Add-ons' link.

Check the box next to collective.lazysizes and click the 'Activate' button.

How does it work

This package adds a transformer to the transform chain to integrate lazysizes into Plone.

The transformer looks for all the <img>, <iframe> and <blockquote> tags inside the content and does the following:

  • appends a lazyload class
  • if the tag is an <img>, transforms the src attribute into a data-src and uses a gray square in its place to maintain valid HTML code (this placeholder is loaded using the data URI scheme to avoid a new request to the server)
  • if the tag is an <iframe>, transforms the src attribute into a data-src
  • if the tag is a <blockquote> containing a tweet, it adds a data-twitter attribute and removes the <script> tag associated with the Twitter widget to avoid a useless request

These transforms can be applied to all users or only to anonymous.

Look Ma! No Resource Registries

This add-on uses a very opinionated approach on how to handle static resources in Plone. We just deprecated resource registries in favor of a simpler approach: a viewlet in plone.htmlhead. This simplifies maintainance among multiple Plone versions and avoids bundling of unrelated resources.

Development

We use webpack to process static resources on this package. Webpack processes SCSS and JS files, minifies the resulting CSS and JS, and optimizes all images.

To contribute, you should start the instance in one shell and start webpack watcher on another with the following command:

$ bin/watch-lazysizes

Then go to webpack/app folder and edit SCSS and JS files; webpack watcher will automatically create the final resources in the right place.

There are also other commands added to handle more complex scenarios.

The following command will set the buildout node installation in the system PATH, this way you can use webpack as described on their documentation.

$ bin/env-lazysizes

The following command generates JS and CSS without the minify step (it can be used to check the code being generated in a human readable way).

$ bin/debug-lazysizes

The following command rebuilds static files and exit (insted of keep watching the changes):

$ bin/build-lazysizes