melinath / django-daguerre

On-the-fly image manipulation for Django.
http://django-daguerre.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
85 stars 15 forks source link

Toggle lazy-load in the project's settings #101

Open fitodic opened 7 years ago

fitodic commented 7 years ago

Greetings! Firstly, great job developing this library! Secondly, the documentation states that the adjust tag renders as a URL to the adjusted image as lazily as possible. This is a great feature, but have you ever considered setting the generate parameter project-wide?

To make thing clearer, here's an example. A site allows the users to upload their own images and there is a predefined set of variations that can be diplayed, e.g. only thumbnails of 300x200px and 600x400px. The process of generating these variations can be triggered after uploading the image.

In order to be backwards compatible, this setting could be set in the project's settings and the default value would remain False. Therefore, if the project does not have the variable set, it would maintain its previous functionality.

We already have a working example. I'd be happy to implement it and send you a pull request.

What are your thoughts on the matter?

Sincerely, Filip Todic

melinath commented 7 years ago

Have you already looked at daguerre-preadjust? Does it meet your needs?

It sounds like you're looking for a solution that does the adjustment creation when the image is uploaded rather than when it's loaded, so a cron solution might not be exactly what you're looking for. Rather than just adding the GENERATE setting, I'd probably want to see something that's hooked into DAGUERRE_PREADJUSTMENTS, for example by adding a DAGUERRE_PREADJUST_ON_SAVE setting and adding a post_save listener that applies all relevant adjustments.

fitodic commented 7 years ago

Thanks for the feedback! We've analyzed the situation in detail. Unfortunately, none of the currently available solutions meet our needs. We are not able to customize our custom logic at the moment to the point of providing a generic solution that could be pushed upstream.

Baring that in mind, I suggest we close this issue for the time being. Thanks for your help!

melinath commented 7 years ago

Eh, It's still a useful ticket. I'd be curious to know more about your use case if it's something you'd be willing to share?

fitodic commented 7 years ago

We use daguerre's adjust tag in several places and a global generate=True settings suits us because:

  1. We have a large user base that produces its own content (including images). They are free to publish whatever they want, whenever they want (within the bounds of the law of course). We have no control over the published content, and the only requirement is that they see the results, i.e. variations, in near real-time. Furthermore, the machinery we have in place is capable of handling that load.
  2. The lazy-rendering feature results in caching issues and is therefore not an option. The generated AJAX URLs are cached and for a while (the duration depends on the cache settings of a particular tag), the users are receiving these URLs instead of the real ones. This violates the requirement mentioned above. Furthermore, this is also an SEO issue, meaning that the same content (in this case an image) has different URLs.
  3. A cronjob calling the preadjust command would not be suitable for both production and development purposes. The production requirements are already explained above (issue 1.). As to the development requirements, frontend developers are free to set any dimension parameters they choose. Even if we know most of the variations, there is no way of anticipating their needs.
melinath commented 7 years ago

When you say the AJAX URLs are cached, do you mean that your site is using django {% cache %} tags? Or do you mean cached in the browser? Or something else? Are images maybe being updated in place, i.e. so that the same storage path would point to two different images?

There is definitely not an intent on our end that those URLs should be cached anywhere. The lazy rendering should work just fine for near real-time viewing of image variations. (I'm not addressing the SEO side of things intentionally right now because that's less high priority than a potential caching issue.)

fitodic commented 7 years ago

When using template tags, we are using Django's template fragment caching as described in the official documentation. When the template was first compiled/rendered, the first URL that the template tag received was cached for the period of time specified in the cache tag.