[IMP] website: ir_qweb - add lazyloading by default on img

closes odoo/odoo#55945

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Jeremy Kersten
2020-08-14 13:49:30 +00:00
parent eb1e28ced3
commit 617c716aea
2 changed files with 7 additions and 4 deletions
+3
View File
@@ -50,6 +50,9 @@ class QWeb(models.AbstractModel):
atts = super(QWeb, self)._post_processing_att(tagName, atts, options)
if tagName == 'img' and 'loading' not in atts:
atts['loading'] = 'lazy' # default is auto
if options.get('inherit_branding') or options.get('rendering_bundle') or \
options.get('edit_translations') or options.get('debug') or (request and request.session.debug):
return atts
+4 -4
View File
@@ -50,15 +50,15 @@ class TestQweb(TransactionCaseWithUserDemo):
<script type="text/javascript" src="http://test.cdn%(js)s"></script>
</head>
<body>
<img src="http://test.external.link/img.png"/>
<img src="http://test.cdn/website/static/img.png"/>
<img src="http://test.external.link/img.png" loading="lazy"/>
<img src="http://test.cdn/website/static/img.png" loading="lazy"/>
<a href="http://test.external.link/link">x</a>
<a href="http://test.cdn/web/content/local_link">x</a>
<span style="background-image: url('http://test.cdn/web/image/2')">xxx</span>
<div widget="html"><span class="toto">
span<span class="fa"></span><img src="http://test.cdn/web/image/1">
span<span class="fa"></span><img src="http://test.cdn/web/image/1" loading="lazy">
</span></div>
<div widget="image"><img src="http://test.cdn/web/image/res.users/%(user_id)s/image_1920/%(filename)s" class="img img-fluid" alt="%(alt)s"/></div>
<div widget="image"><img src="http://test.cdn/web/image/res.users/%(user_id)s/image_1920/%(filename)s" class="img img-fluid" alt="%(alt)s" loading="lazy"/></div>
</body>
</html>""" % {
"js": attachments[0].url,