Skip to content

Commit e64817e

Browse files
author
Petr Glotov
committed
added is_preload flag
1 parent 990d9ec commit e64817e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

webpack_loader/templatetags/webpack_loader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
@register.simple_tag
11-
def render_bundle(bundle_name, extension=None, config='DEFAULT', attrs=''):
12-
tags = utils.get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs)
11+
def render_bundle(bundle_name, extension=None, config='DEFAULT', attrs='', is_preload=False):
12+
tags = utils.get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs, is_preload=is_preload)
1313
return mark_safe('\n'.join(tags))
1414

1515

@@ -19,6 +19,8 @@ def webpack_static(asset_name, config='DEFAULT'):
1919

2020

2121
assignment_tag = register.simple_tag if VERSION >= (1, 9) else register.assignment_tag
22+
23+
2224
@assignment_tag
2325
def get_files(bundle_name, extension=None, config='DEFAULT'):
2426
"""

webpack_loader/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from .loader import WebpackLoader
44

5-
65
_loaders = {}
76

87

@@ -31,7 +30,7 @@ def get_files(bundle_name, extension=None, config='DEFAULT'):
3130
return list(_get_bundle(bundle_name, extension, config))
3231

3332

34-
def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
33+
def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs='', is_preload=False):
3534
'''
3635
Get a list of formatted <script> & <link> tags for the assets in the
3736
named bundle.
@@ -51,8 +50,8 @@ def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
5150
).format(chunk['url'], attrs))
5251
elif chunk['name'].endswith(('.css', '.css.gz')):
5352
tags.append((
54-
'<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
55-
).format(chunk['url'], attrs))
53+
'<link type="text/css" href="{0}" rel={2} {1}/>'
54+
).format(chunk['url'], attrs, '"stylesheet"' if not is_preload else '"preload" as="style"'))
5655
return tags
5756

5857

0 commit comments

Comments
 (0)