Skip to main content

Automatically add dimension attributes to all <img> tags in a response to improve rendering speed on the client.

Project description

Automatically add dimension attributes to all &lt;img&gt; tags in a response to improve rendering speed on the client.

Rationale

Specifying image dimensions in HTML improves both percieved and actual client-side rendering performance by preventing reflow. However, maintaining explicit dimensions in templates is tedious and impractical in some cases. This middleware solves that in a plug-and-play manner by automatically setting dimensions in all &amp;img&amp; tags in a response.

Requirements

  • django-celery to run image fetch and dimensions calculations in the background

  • PIL

  • A cache that is shared between web server and celery (e.g. memcached)

Installation

  1. Run pip install django-image-dimensions

  2. Add ‘imagedimensions’ app to INSTALLED_APPS

Usage

For a quick test-drive add ‘imagedimensions.middleware.ImageDimensionsMiddleware’ to MIDDLEWARE_CLASSES. However, this is not suitable for production use as it adds an overhead to every request. For production, replace {% load cache %} in your templates with {% load imgdimensions %}.

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

django-image-dimensions-0.0.4.tar.gz (3.8 kB view hashes)

Uploaded Source

Supported by

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