-
Notifications
You must be signed in to change notification settings - Fork 4
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
chore: avoid lazy loading for print #493
base: develop
Are you sure you want to change the base?
Conversation
…sign into OPS-11125-print-images
js/cd-print.js
Outdated
$('img').each(() => { | ||
$(this).removeAttr('loading'); |
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.
$
assumes that jquery is globally available. Iframe also can be lazy loaded.
So better be more generic and use vanilla JS:
$('img').each(() => { | |
$(this).removeAttr('loading'); | |
document.querySelectorAll('[loading="lazy"]').forEach(element => { | |
element.removeAttribute('loading'); | |
}); |
Notes
This may not be enough to force load the images and iframes, depending on the browsers. This needs testing and if that doesn't work, re-setting the src
attribute for example may do the trick.
This may also require adjusting the waiting time on the snap tool.
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.
Thanks, I've made the changes and a feature branch for RWR with this as a patch so I can test it there.
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.
The patch is now on the feature instance, where it seems to be working as intended: https://stage.response-reliefweb-int.ahconu.org/fr/central-african-republic/bulletin-humanitaire/reponse-durgence
js/cd-print.js
Outdated
// Remove lazy loading before printing. | ||
window.addEventListener('beforeprint', (event) => { | ||
document.querySelectorAll('[loading="lazy"]').forEach(element => { | ||
element.removeAttr('loading'); |
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.
element.removeAttr('loading'); | |
element.removeAttribute('loading'); |
removeAttr
is jQuery, please use removeAttribute.
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.
ouch. sorry.
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.
The code looks ok but not sure if that fixes the problems. As mentioned in the ticket, what was tested might not have been a good example.
I would be hesitant to add another piece of javascript to all the sites using the common design without ensuring that it actually does something useful.
Agreed, adding 'blocked' label until I can prove this helps. |
Refs: OPS-11125
Types of changes
Description
Remove lazy loading before printing.
Steps to reproduce the problem or Steps to test
https://humanitarian.atlassian.net/browse/OPS-11125
Impact
This adds a snippet of js to all pages, to avoid printing lazy-loading images. This may be too much.
PR Checklist