[FIX] web, base: review lazy loaded <script> definitions
The assets bundle system allows to generate `<script>` elements whose resource is meant to be lazy loaded. In that case, a "data-src" is used instead of "src" directly as attribute. This is valid HTML code: "src" is not required. However... this lazy loading system also automatically added `defer="defer"` which makes the "src" attribute required, thus failing W3C validation. Now, we only add "data-src" and the `defer="defer"` part is added on the client-side, once the "data-src" is switched to "src". Note that this "defer" attribute may not be needed in this case at all, but it cannot hurt. Part-of: odoo/odoo#120311
This commit is contained in:
@@ -103,6 +103,7 @@ function _loadScripts(scripts, index) {
|
||||
}
|
||||
var script = scripts[index];
|
||||
script.addEventListener('load', _loadScripts.bind(this, scripts, index + 1));
|
||||
script.setAttribute('defer', 'defer');
|
||||
script.src = script.dataset.src;
|
||||
script.removeAttribute('data-src');
|
||||
}
|
||||
|
||||
@@ -191,7 +191,9 @@ class AssetsBundle(object):
|
||||
src = self.get_debug_asset_url(name=js_attachment.name, extension='') if is_debug_assets else js_attachment[0].url
|
||||
attr = dict([
|
||||
["async", "async" if async_load else None],
|
||||
["defer", "defer" if defer_load or lazy_load else None],
|
||||
# lazy_load will add defer in JS otherwise this is not W3C valid
|
||||
# (defer is probably not needed there anyways)
|
||||
["defer", "defer" if defer_load else None],
|
||||
["type", "text/javascript"],
|
||||
["data-src" if lazy_load else "src", src],
|
||||
['data-asset-bundle', self.name],
|
||||
|
||||
@@ -2512,7 +2512,9 @@ class IrQWeb(models.AbstractModel):
|
||||
"type": mimetype,
|
||||
}
|
||||
attributes["data-src" if lazy_load else "src"] = path
|
||||
if defer_load or lazy_load:
|
||||
if defer_load:
|
||||
# lazy_load will add defer in JS otherwise this is not
|
||||
# W3C valid (defer is probably not needed there anyways)
|
||||
attributes["defer"] = "defer"
|
||||
elif is_css:
|
||||
tag = 'link'
|
||||
|
||||
Reference in New Issue
Block a user