-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add image lazy loading using wagtail-lazyimages plugin #2081
Conversation
f4deaa2
to
bb8f0ee
Compare
Codecov Report
@@ Coverage Diff @@
## master #2081 +/- ##
==========================================
+ Coverage 88.00% 97.14% +9.14%
==========================================
Files 328 157 -171
Lines 14759 4934 -9825
Branches 1030 0 -1030
==========================================
- Hits 12988 4793 -8195
+ Misses 1532 141 -1391
+ Partials 239 0 -239 Continue to review full report at Codecov.
|
d220bc0
to
4e9de87
Compare
4e9de87
to
83d569c
Compare
83d569c
to
cdd30bf
Compare
cdd30bf
to
e04889a
Compare
e04889a
to
972deeb
Compare
972deeb
to
c3001c4
Compare
c3001c4
to
720e83a
Compare
@HamzaIbnFarooq I was able to test it on
` |
Thanks @arslanashraf7, for the review, that filter ( Updated: |
|
||
<div class="cover-image"> | ||
<div class="cover-image-frame"> | ||
{% if courseware_page.thumbnail_image %} | ||
<img src="{% image_version_url courseware_page.thumbnail_image "fill-275x155" %}" alt="{{ courseware_page.thumbnail_image.title }}" /> | ||
{% wagtail_image_lazy_load courseware_page.thumbnail_image fill-275x155 alt=courseware_page.thumbnail_image.title class="wagtail-lazy-load" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we wouldn't need to specify the same class for every one of these images. It would be nice to have a default class and the option to extend. A param like addedClass
might make sense. Also, the class can just be called lazy
instead of wagtail-lazy-load
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree with your suggestions but I am trying to keep it as simple as we can. The issue is with the template tag we are using, when we create a simple_tag @register.simple_tag()
it works as a function to which you can pass values and do some **kwargs stuff but in our case, we have to use @register.tag(name="xyz")
as the function have to call another wagtail's tag named image.
Both the tags have different parsing techniques. So adding a new attribute makes the whole process complicated and messy.
As far as changing the name of wagtail-lazy-load
to lazy
is concerned, I have updated that.
return "" | ||
|
||
raw_img_tag = super().render(context) | ||
parsed_content = BeautifulSoup(raw_img_tag, "lxml").img |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is clean enough in terms of avoiding code repetition, and it's unfortunate that the library doesn't give us extension options, but I'm not sure I agree with this approach of generating the image tag with the library implementation, parsing it as XML, adding attributes, and casting it as a string again. I think I would prefer even a regex replace – after all, we're just tacking on the same ?v=<hash>
to the end of those two attribute values. The XML parsing just seems like more work than we need to be doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
static/js/wagtail_lazy_load.js
Outdated
threshold: 0 | ||
}; | ||
|
||
const imgs = document.querySelectorAll(".wagtail-lazy-load"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selector can be changed to img.lazy
if you change that class name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
@HamzaIbnFarooq Sorry, I should have looked into this in my earlier review, but I noticed an issue with this library. Wagtail generates images on the fly depending on how you render them. This caused major performance issues for us, so we introduced a change to cache those generated images in Redis (#2029). Unfortunately it looks like the |
@gsidebo Thanks for the detailed review. I didn't know about the whole rendition process, I spent some time understanding it but as you said it's somewhat challenging to integrate into our scenario. |
Closing this. The library didn't suit our needs |
Pre-Flight checklist
What are the relevant tickets?
#2065
What's this PR do?
Uses wagtail-lazyimages plugin and customizes it in a wrapper template tag (
wagtail_image_lazy_load
) to achieve enhanced cachingNOTE:
"height-110|format-png"
are not supported by Wagtail-lazyimages plugin so I couldn't use it in learning-techniques.html inorder to use it we need to change that filter to something likemax-150x150|format-png
I have changed this in this commit