Integration of lazysizes, a lightweight lazy loader, into Plone.
Project description
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:
CartaCapital (BR)
Conversa Afiada (BR)
Portal Brasil 2016 (BR)
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:
Edit your buildout.cfg and add add the following to it:
[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 are applied to anonymous users only.
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. The final JS file is also a UMD package, which provides compatibility with most popular script loaders.
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 its 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
Changelog
4.1.1.1 (2018-09-10)
Avoid ImportError while running upgrade step v10 (fixes #63). [hvelarde]
4.1.1 (2018-09-06)
Deprecate resource registries; instead, we now use a viewlet in plone.htmlhead to load JavaScript code. This simplifies maintainance of the add-on among multiple Plone versions. [hvelarde]
Upgrade lazysizes to v4.1.1. [hvelarde]
Add lazysizes print plugin; this plugin will automatically unveil all elements as soon as a print is detected even if the given lazyload image isn’t in the viewport (fixes #50). [thet, hvelarde]
Remove unused collective.lazysizes.ImageScales vocabulary. [hvelarde]
Process static resources using webpack. [rodfersou]
Avoid ValueError when upgrading from profile version 3 (fixes #46). [hvelarde]
4.0.1 (2017-11-20)
Upgrade lazysizes to v4.0.1. Twitter plugin is now CommonJS compatible. [hvelarde]
Require plone.app.registry >=1.5. Refs #42 [erral]
3.1 (2017-10-02)
Add German translations. [thet]
Add explicit i18n message ids instead of implicit based on the translation string. [thet]
Fix Plone 5 compatibility. [thet]
Extend the uninstall profile with more de-registrations. [thet]
Fix the blacklist XPath selector to also match elements with the class directly set on it. [thet]
Add configlet option to enable lazy loading for authenticated users. [hvelarde]
Avoid possible overriding of css_class_blacklist while upgrading. [hvelarde]
Avoid possible ConfigurationConflictError on upgrade step registration. [hvelarde]
3.0.0 (2017-03-09)
Update lazySizes to v3.0.0. [hvelarde]
Remove respimg polyfill plugin. [hvelarde]
Fix UnicodeEncodeError on logger. [hvelarde]
2.0.5rc1 (2016-10-28)
Clean up configlet; the image_candidates field was removed as the intended functionality will be included in Plone’s core in the near future (see PLIP 1483). [hvelarde]
Remove dependency on five.grok. [hvelarde]
Update lazysizes to v2.0.5. [hvelarde]
Pin version of Products.ResourceRegistries >=2.2.12 to fix upgrade step. [rodfersou, hvelarde]
2.0.0b1 (2016-08-11)
1.5.0b1 (2016-05-25)
Embedded tweets are now also lazy loaded (closes #15). [aFarkas, rodfersou, hvelarde]
Package is now compatible with Plone 5.0 and Plone 5.1. [hvelarde]
1.5.0a1 (2016-04-07)
Use data URI scheme for image placeholder to save one additional request (closes #8). [hvelarde]
Brazilian Portuguese and Spanish translations were added. [hvelarde]
Deal better with <img> tags with no src attribute; log an error message with the request URL (closes #11). [hvelarde]
Package is now compatible with Plone 5. [hvelarde]
Remove dependency on Products.CMFQuickInstallerTool. [hvelarde]
Update lazysizes and respimg polyfill extension to v1.5.0. [hvelarde]
1.4.0a1 (2016-02-23)
Add option to list class identifiers that will not be processed for lazy loading. <img> and <iframe> elements with that class directly applied to them, or to a parent element, will be skiped (closes #5). [rodfersou, hvelarde]
Update lazysizes and respimg polyfill extension to v1.4.0. [hvelarde]
Use a blank image instead of a spinner as placeholder. [hvelarde]
Logging now uses debug level instead of info. [hvelarde]
1.0a1 (2016-01-05)
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for collective.lazysizes-4.1.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc5d1717a4893a4a5cd251fe629a6af5c5d9b1a8d0946afc92801983545549cb |
|
MD5 | a82c3a9901b20e55cf837d0da7605e47 |
|
BLAKE2b-256 | c038f9970b9ca1fb3f8a73caf6db74a476ee2a829a60c91c119aaa3cd17cde3c |
Hashes for collective.lazysizes-4.1.1.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 718030677017f4e5c145cc8a0829076e3e04f5f66914f760f5bb642e7d984c8a |
|
MD5 | 0b35d2be4ae59193b207e84d4ff2e670 |
|
BLAKE2b-256 | 0859b1ea070ad2568458d87999c40b58aa0d0c7d1c68f73142a7e1a06b7625fe |