Skip to content

Commit 1fab452

Browse files
committed
Added skip_common_chunks argument to render_bundle to address duplicate
script tag issue #289. Uses context to store a list of all loaded tags by default and skips them if the option is set for that invocation of render_bundle
1 parent c000c37 commit 1fab452

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

webpack_loader/templatetags/webpack_loader.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77
register = template.Library()
88

99

10-
@register.simple_tag
11-
def render_bundle(bundle_name, extension=None, config='DEFAULT', suffix='', attrs='', is_preload=False):
10+
@register.simple_tag(takes_context=True)
11+
def render_bundle(context, bundle_name, extension=None, config='DEFAULT', suffix='', attrs='', is_preload=False, skip_common_chunks=False):
1212
tags = utils.get_as_tags(
1313
bundle_name, extension=extension, config=config,
1414
suffix=suffix, attrs=attrs, is_preload=is_preload
1515
)
16+
used_tags = context.get("webpack_loader_used_tags", [])
17+
if not used_tags:
18+
context["webpack_loader_used_tags"] = []
19+
if skip_common_chunks:
20+
tags = [mark_safe(tag) for tag in tags if tag not in used_tags]
21+
22+
context["webpack_loader_used_tags"] = context["webpack_loader_used_tags"] + tags
23+
1624
return mark_safe('\n'.join(tags))
1725

18-
1926
@register.simple_tag
2027
def webpack_static(asset_name, config='DEFAULT'):
2128
return utils.get_static(asset_name, config=config)

0 commit comments

Comments
 (0)