Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 5 column 16
---
title: Optimize storefront script loading
issue: NEXT-15917
author: Tobias Berge
author_email: [email protected]
author_github: @tobiasberge
---
- Deprecated script twig blocks inside
Resources/views/storefront/base.html.twig
- Deprecated block
base_script_token
- Use blocklayout_head_javascript_token
insideResources/views/storefront/layout/meta.html.twig
instead - Deprecated block
base_script_router
- Use blocklayout_head_javascript_router
insideResources/views/storefront/layout/meta.html.twig
instead - Deprecated block
base_script_breakpoints
- Use blocklayout_head_javascript_breakpoints
insideResources/views/storefront/layout/meta.html.twig
instead - Deprecated block
base_script_csrf
- Use blocklayout_head_javascript_csrf
insideResources/views/storefront/layout/meta.html.twig
instead - Deprecated block
base_script_wishlist_state
- Use blocklayout_head_javascript_wishlist_state
insideResources/views/storefront/layout/meta.html.twig
instead - Deprecated block
base_script_hmr_mode
- Use blocklayout_head_javascript_hmr_mode
insideResources/views/storefront/layout/meta.html.twig
instead
- Deprecated block
- Changed
Resources/app/storefront/src/main.js
and executePluginManager.initializePlugins()
on theDOMContentLoaded
event - Changed
<script>
tags in blockbase_script_hmr_mode
inside templateResources/views/storefront/base.html.twig
and removedasync
attribute - Changed
<script>
tag in blockcomponent_head_javascript_recaptcha
inside templateResources/views/storefront/component/recaptcha.html.twig
and removedasync
attribute
All base_body_script
child blocks and their <script>
tags are moved from Resources/views/storefront/base.html.twig
to Resources/views/storefront/layout/meta.html.twig
. The block base_body_script
itself remains in the base.html.twig
template to offer the option to inject scripts before the </body>
tag if desired.
The scripts got a defer
attribute to allow downloading the script file while the HTML document is still loading. The script execution happens after the document is parsed.
Example for a <script>
extension in the template:
{% sw_extends '@Storefront/storefront/base.html.twig' %}
{% block base_script_router %}
{{ parent() }}
<script type="text/javascript" src="extra-script.js"></script>
{% endblock %}
{% sw_extends '@Storefront/storefront/layout/meta.html.twig' %}
{% block layout_head_javascript_router %}
{{ parent() }}
<script type="text/javascript" src="extra-script.js"></script>
{% endblock %}