Implements preload option for scripts

This commit is contained in:
João Lins 2021-08-16 18:40:50 -03:00
parent ae7d5b86f6
commit 4d87836df6

View file

@ -62,9 +62,14 @@ def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs='', is_prel
tags = []
for chunk in bundle:
if chunk['name'].endswith(('.js', '.js.gz')):
tags.append((
'<script src="{0}" {1}></script>'
).format(chunk['url'], attrs))
if is_preload:
tags.append((
'<link rel="preload" as="script" href="{0}" {1}/>'
).format(chunk['url'], attrs))
else:
tags.append((
'<script src="{0}" {1}></script>'
).format(chunk['url'], attrs))
elif chunk['name'].endswith(('.css', '.css.gz')):
tags.append((
'<link href="{0}" rel={2} {1}/>'