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 <img> 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 &img& 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
Run pip install django-image-dimensions
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
Hashes for django-image-dimensions-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ea669759d5b660c1cb79409caa4de4e22228ea9c64ddabdcedd6f5cf5af41c0 |
|
MD5 | dd0d2f3494620305fd91410522f40610 |
|
BLAKE2b-256 | 1bc908a42ab8b2a3ecba0f90444ebcd0fb4872e73a4f4d2a5f56b9e0b31de6e4 |