Skip to main content

A wagtail plugin that generates tiny blurry placeholder images for lazy-loading.

Project description

Wagtail Lazy Images

Template tags that generate tiny blurry placeholder images alongside your wagtail images in order to lazy-load them medium.com style.

Installing

Install using pip: pip install wagtail-lazyimages

Usage

  1. Add wagtail_lazyimages to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'wagtail_lazyimages',
    ]
    
  2. Load the lazyimages_tags template tag library in your template:

    {% load "lazyimages_tags" %}
    
  3. Replace wagtail's image tag with lazy_image for images that should lazy load:

    {% lazy_image page.photo width-960 class="lazy" %}
    

    This template tag behaves just like wagtail's image tag with the exception that it generates an additional scaled down and blurred placeholder image. The URL of the placeholder image will appear in the src attribute of the image tag while the large version will be referenced in data-src:

    <img src="/path/to/placeholder-image.jpg" data-src"/path/to/image.jpg" class="lazy" />
    
  4. In the front end: Implement the lazy loading functionality yourself or use a dedicated JavaScript library like lozad.js:

    const observer = lozad('.lazy');
    observer.observe();
    

Image in context variable

If you need to assign the image data to a template variable using Django's as syntax, use the provided lazy_image_url template tag for getting just the URL of the placeholder image:

{% load "lazyimages_tags" %}

{% image page.photo width-960 as img %}

<img data-src="{{ img.url }}" src="{% lazy_image_url img %}" width="{{ img.width }}"
     height="{{ img.height }}" alt="{{ img.alt }}" />

Alternative attribute

If you want to use a different attribute for referencing the original image than data-src use the parameter lazy_attr for that:

{% lazy_image page.photo width-960 lazy_attr="data-lazy-url" class="lazy" %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail-lazyimages-0.1.5.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file wagtail-lazyimages-0.1.5.tar.gz.

File metadata

  • Download URL: wagtail-lazyimages-0.1.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.35.0 CPython/3.6.8

File hashes

Hashes for wagtail-lazyimages-0.1.5.tar.gz
Algorithm Hash digest
SHA256 bd6e6c7c7d2890a56ad4fbc59cc031b4d0917ba8a964ab8f4494463e30f9d155
MD5 0b4b725de3def4c68ceaa6ef8f937bf2
BLAKE2b-256 f0792279bd91d3c5b31ba7925b179e727ea0e2219778f74345c31cf559381a56

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page